Skip to content

Commit

Permalink
Update formalist to support lists of many forms (#33)
Browse files Browse the repository at this point in the history
* Add option to configure the name of the csrf token submitted in a confirm action.

This allows us to use roneo with the Hanami token name `_csrf_token`.

* Update formalist-standard-react dependency to version 4.3.0

Co-authored-by: Andrew Croome <[email protected]>
Co-authored-by: Andy McCray <[email protected]>
  • Loading branch information
3 people authored Apr 7, 2022
1 parent 07c5181 commit 52ec90c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
5 changes: 3 additions & 2 deletions lib/confirm-action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports.default = confirmAction;
function confirmAction(el, props) {
var question = props.question;
var action = props.action;
var csrfTokenName = props.csrf_token_name || '_csrf';

function onClick(e) {
// Don't do anything if we can’t work out the action
Expand All @@ -33,11 +34,11 @@ function confirmAction(el, props) {

// Append the CRSF token if it exists
if (props.method !== 'GET') {
var csrfElement = document.querySelector('meta[name=_csrf]');
var csrfElement = document.querySelector('meta[name=' + csrfTokenName + ']');
if (csrfElement) {
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', '_csrf');
input.setAttribute('name', csrfTokenName);
input.setAttribute('value', csrfElement.getAttribute('content'));
form.appendChild(input);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"fastclick": "^1.0.6",
"fontfaceobserver": "^2.0.13",
"formalist-serialize-react": "^1.0.6",
"formalist-standard-react": "^4.1.4",
"formalist-standard-react": "^4.3.0",
"immutable": "^3.8.2",
"nodemon": "^1.18.6",
"prop-types": "^15.6.0",
Expand Down
5 changes: 3 additions & 2 deletions src/confirm-action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export default function confirmAction (el, props) {
const question = props.question
const action = props.action
const csrfTokenName = props.csrf_token_name || '_csrf'

function onClick (e) {
// Don't do anything if we can’t work out the action
Expand All @@ -27,11 +28,11 @@ export default function confirmAction (el, props) {

// Append the CRSF token if it exists
if (props.method !== 'GET') {
let csrfElement = document.querySelector('meta[name=_csrf]')
let csrfElement = document.querySelector('meta[name=' + csrfTokenName + ']')
if (csrfElement) {
let input = document.createElement('input')
input.setAttribute('type', 'hidden')
input.setAttribute('name', '_csrf')
input.setAttribute('name', csrfTokenName)
input.setAttribute('value', csrfElement.getAttribute('content'))
form.appendChild(input)
}
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1939,23 +1939,23 @@ form-data@^2.3.1:
combined-stream "1.0.6"
mime-types "^2.1.12"

"formalist-compose@^2.0.1 || ^3.0.1", "formalist-compose@^2.0.1 || ^3.0.2", formalist-compose@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/formalist-compose/-/formalist-compose-3.0.2.tgz#da3734876e59801a207c7120c40e100a4ebf49d8"
integrity sha512-AEII2jPLagae09w7LEYQvSqdFehSyNPPN8qpe3Xg8IQPRZHXSGtxoDC7YMSCYQjL2bo+iYQZIPaG3T7xDyA+HA==
"formalist-compose@^2.0.1 || ^3.0.2", formalist-compose@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/formalist-compose/-/formalist-compose-3.1.0.tgz#04e8e6d12b042eabfb7a52da2ab2842a92ef6c91"
integrity sha512-jtQqG/pwsfeW+DELeyJ0+1by4SLQc8nVp97DTpUJ5h7fyxq7fB4NWReZCWeLeOOhPs8DHkBZ0gKUQnocOaz/jg==
dependencies:
component-emitter "1.2.1"
formalist-validation "^1.0.0"
immutable "^3.7.6"
redux "^3.3.1"
redux-batched-actions "^0.1.2"

formalist-data-object-renderer@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/formalist-data-object-renderer/-/formalist-data-object-renderer-1.0.3.tgz#12dddcbc0a7fcdcd01fce6550ee72ad355d11bd7"
integrity sha512-5QUiDR35J28H+S5Fr6ujES8t9zDU2S1WixaxwSYuJpFko9NCFmnHtN64rW7DDGfZqFZTKYW+oYU4zfurKAvV0A==
formalist-data-object-renderer@^1.0.3, formalist-data-object-renderer@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/formalist-data-object-renderer/-/formalist-data-object-renderer-1.1.1.tgz#d54288108c07140e0d1db66faed9639a4488bcf3"
integrity sha512-qk4aI0HRTrTA2uSsiThznqPQQVNSY4J8pGvUl/rvY7+7FrXsmqNkKMaklSEpyk7oyBsnDJAXyO+xgsZZH+NzmA==
dependencies:
formalist-compose "^2.0.1 || ^3.0.1"
formalist-compose "^3.1.0"

formalist-serialize-react@^1.0.6:
version "1.0.6"
Expand All @@ -1966,10 +1966,10 @@ formalist-serialize-react@^1.0.6:
formalist-data-object-renderer "^1.0.3"
immutable "^3.7.6"

formalist-standard-react@^4.1.4:
version "4.1.4"
resolved "https://registry.yarnpkg.com/formalist-standard-react/-/formalist-standard-react-4.1.4.tgz#031d311ef9fa5be2f1cad0410ef15afa5a7c9698"
integrity sha512-KMhJK4quF7t3zDZRqRqzF83aV8ficlIXVxHG+85nEFKrq44RnedW0mMDM4AupBF9vj5o6N5Wqax6I22czdOvlg==
formalist-standard-react@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/formalist-standard-react/-/formalist-standard-react-4.3.0.tgz#d66a995c7e6d500403d81c14bcf73bd5360c30fe"
integrity sha512-aTpk0lMSYQXz8iW+/46C4Kvs+n3KLCIJ/UOUQZCGcDBSd8kZOypY949/twLIksNRiGU2adBJb/Wks2T8O2bhQA==
dependencies:
uid "^0.0.2"
attache-upload "^2.1.1"
Expand All @@ -1987,8 +1987,8 @@ formalist-standard-react@^4.1.4:
emotion "^8.0.8"
es6-promise "^4.1.1"
exif-js "2.3.0"
formalist-compose "^3.0.2"
formalist-data-object-renderer "^1.0.3"
formalist-compose "^3.1.0"
formalist-data-object-renderer "^1.1.1"
fuzzy "0.1.3"
is-number "^4.0.0"
lodash.assigninwith "^4.2.0"
Expand Down

0 comments on commit 52ec90c

Please sign in to comment.