-
Notifications
You must be signed in to change notification settings - Fork 38
Unexpected array values #73
Comments
I haven't verified, but your explanation sounds plausible. Polymer has been tough to support due to the instability of the library and the community of elements. At some point, I believe all of these Polymer custom input fields hid the underlying native form fields in the shadow DOM. It looks like the Polymer team has abandoned shadow DOM entirely as of v1, replacing it with something they call "shady DOM". No idea what "shady DOM" is, and I don't really care. I have no use for Polymer anyway. One possible fix may be for me to modify ajax-form to start by looking at the children of a |
Just remembered that the code in ajax-form that attempts to related custom elements to form fields may be the cause of this issue. The final sentence of my above comment can probably just be applied to elements located during the custom element form field that have native form field matches. In that case, the custom field should be thrown out, provided the match is a descendent of the custom field. |
Looking around at other form serializers, the Polymer iron-form may be a good reference. To handle Polymer form elements it listens for the iron-form-element-register event but since Polymer 1.0 is exposing the underlying input elements then maybe using HTMLFormElement.elements is enough to capture all the elements? It looks like the iron-form is using the HTMLFormElement.elements property at least in-part, but they also handle some checkbox behavior. |
I think an adjustment to the existing custom element selector code is all
|
Oh yea, definitely avoid their internal events :P I was just curious to see how Polymer was handling it. Sounds good! |
Can you provide me with the composed DOM of your Better yet, a link to a live page where this can be reproduced...? |
Polymer 1.0 changes cause an unexpected change in resulting json in ajax-form: rnicholus/ajax-form#73 Switching to iron-form until the issue is resolved
Nevermind, I just looked at your initial post again, missed the screenshot the first time around. It seems like a bug in paper-input. It really shouldn't be passing the |
Hmm, I'm not convinced that it would be a Polymer bug. The ajax-form behavior of taking all elements that have a I like the clarity of this approach over the DOM selection rules used by HTMLFormElements.elements and I think it's just a question of how the library handles the case of nested elements containing name attributes.
I think it would be reasonable to say that the only element that would be part of serialization would be div[name="hello"] and maybe even give some console.warns that div[name="world"] will be ignored. |
I really don't see a good reason why
That's correct, and this was an explicit decision on my part. Relying solely on The real question here is, which element should ajax-form extract the value from: |
I also want to point out that this is not exactly how ajax-form functions. It only uses this logic for custom elements. It checks for |
One case I can imagine is for accessibility on screen readers, etc, that would not be aware of custom elements. If a screen reader was to look through the form in the DOM it would follow the In addition, if a user uses a normal form tag (instead of an ajax-form or iron-form, etc) then having the underlying native element allows the form to operate as expected (with the added benefit of pretty material design etc.). I haven't confirmed any of these assumptions, but It seems like they are doing it for web platform compatibility reasons. |
Could be, but that doesn't really address any of the issues I mentioned in my last comment. The fact remains that there is no single approach that will properly support all custom form fields. I'm apprehensive to make any changes to better support Polymer if it means that non-Polymer custom elements will suffer. The easiest solution would be for the Polymer team to ensure the |
sure, then I think it boils down to how the following case mentioned previously should be handled:
Assuming the divs have a value property added to them how would the JSON be serialized? { "hello": "val", "world": "val"} {"hello": {"world": val}} ? // doesn't really make much sense, would need to show relationship and values {"hello": "val"} The current behavior appears to be the first option and it is possible that is the expected behavior for the ajax-form custom element. |
I'm confused. The issue we've been discussing with a custom form field and it's child native form element, both sharing the same |
Yea! I was just trying to see how a general solution, like the one initially proposed would behave (as I understood it). So in the following example:
The current behavior is to serialize to: And the algorithm of ignoring form elements (elements that have an attribute called name and a property called value) that are contained inside another form element would instead ignore the An analogy that would also happen to cover the issue of native elements inside custom elements would be:
Which currently serializes to: But with the ignore nesting algorithm would instead serialize to: |
I'm going to make a couple changes to your markup, as I think this is more representative of what we are discussing. I'm then going to go over a few assumptions. Please let me know if I'm misinterpreting anything: <form action="/endpoint" is="ajax-form" enctype="application/json">
<custom-form-field name="hello">
<input name="hello">
</custom-form-field>
</form> The above markup is the final result of placing a Currently, ajax-form serializes this to: Are we both on the same page? If so, then I think perhaps I can work this in to the next version of ajax-form. Note that the adjustment would not affect form fields with identical names that are siblings, as we would want all of these fields to be sent to the server with all values contained in an array. After all, this is how native |
Going the direction outlined above as of 1a21a11 on hotfix/2.1.1. This will not be a trivial change, as I will now need to maintain a mapping of elements to their field names so I can eliminate any parent/child redundancies. |
Few more adjustments in 2845fa3 before I begin working on this. |
@rajsite I believe I have a workaround in place as of my latest commit to the hotfix/2.1.1 branch. Let me know if this fixes the issue for you. If it does, I'll push out a new hotfix releaase. |
Due to lack of response to this issue and the proposed fix, I'm not convinced that any change is needed on my end. So, I'm going to close this, but will consider reopening if I receive confirmation that this issue needs to be addressed in ajax-form and confirmation that my adjustment in the hotfix branch addresses the issue. |
I recently migrated from ajax-form 1.5.4 to 2.1.0 as part of a polymer 1.0 migration and I have noticed that I now get back an array of values for my paper-input for fields when submitting a form as application/json:
I see in the documentation for the enctype property that if multiple input fields have the same name that this is expected behavior for json data. However this is how my source looks:
I think it is related to a querySelectorAll in ajax-form.js that ends up catching paper-input fields and the child input fields of the paper-input fields, but I haven't walked through to see if that is definitely the case.
When I set a breakpoint we can see that both will be processed but I do not know if the subroutines try to filter out the nested elements:
The text was updated successfully, but these errors were encountered: