Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline form fields need to be psuedo-namespaced #381

Closed
1 task done
robbieaverill opened this issue Sep 11, 2018 · 4 comments
Closed
1 task done

Inline form fields need to be psuedo-namespaced #381

robbieaverill opened this issue Sep 11, 2018 · 4 comments

Comments

@robbieaverill
Copy link
Contributor

robbieaverill commented Sep 11, 2018

With #372 all form fields for inline element editing are given HTML names from their element, e.g. Title, HTML etc.

This not only conflicts between elements but also with the page that the forms sit in. Changing a basic content block's Title then overrides the page's Title when saving (#328).

I propose that we prefix element CMS field names with something unique to them, e.g.:

- input type="text" name="Title"
+ input type="text" name="PageElements[123][Title]"

Where 123 is the element's ID

Pull requests

@robbieaverill
Copy link
Contributor Author

Hmmm. Renaming the fields and getting them into the Redux form's state is easy enough, but redux-form won't render the value for the form field if the name is an array for some reason.

@robbieaverill
Copy link
Contributor Author

robbieaverill commented Sep 11, 2018

I suspect the bug is in how admin converts the form state into something that redux will accept - i.e. form fields like Foo[123][Bar] are added to the state as "Foo[123][Bar]": "value here" but maybe should be nested in the state e.g. "foo": { "123": { "bar": "value here" } } }. I notice that updating the form after its loaded (empty) attempts to change the state to what something more like that.

A workaround we could entertain would be using Foo_123_Bar and serialising the (redux) form state into a hidden field, where the keys are rewritten to what they should be

@robbieaverill
Copy link
Contributor Author

robbieaverill commented Sep 11, 2018

WIP PR: https://github.com/creative-commoners/silverstripe-elemental/tree/pulls/4.0/namespaced-fields

This is working, but using underscored names rather than arrays. If we choose to go this route we'd need to serialise the form data as mentioned above. Another expensive option would be that the page loads its elements and all CMS fields for each element then looks for each field in the request data explicitly... =/

@robbieaverill
Copy link
Contributor Author

Interim solution PR at #386

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant