PolymerElements / iron-autogrow-textarea

Textarea that grows in height as more lines of input are entered
https://webcomponents.org/element/PolymerElements/iron-autogrow-textarea
19 stars 48 forks source link

Name attribute doesn't get attached to the textarea #33

Closed hobberwickey closed 8 years ago

hobberwickey commented 9 years ago

I don't know if this was intentional or not, but the name attribute doesn't connect to the underlying textarea. The docs make it seem like it should. It's an easy fix if it wasn't intentional, simply adding.

name$="[[name]]"

to the textarea definition fixes it and allows the autogrow-textarea to be submitted with a form as you would expect.

EDITED: Sorry, had the wrong values in there.

niknetniko commented 9 years ago

This should get fixed, because this cause paper-textarea to not work as expected as well.

notwaldorf commented 9 years ago

A paper-textarea/ iron-autogrow-textarea can be submitted inside an iron-form, but not inside a native form, since it's a custom element. Binding the name attribute results in the element being submitted twice in an iron-form. If you really need to submit a custom element inside a native form, you can add a hidden input and bind it to the textarea's value:

<input type="hidden" name="foo" value="{{text}}">
<paper-textarea value="{{text}}"></paper-textarea>
hobberwickey commented 9 years ago

It seems then that binding the name attribute isn't a problem with the iron-autogrow-textarea but with iron-form, no? Iron-element's especially should be extending the functionality of native elements not replacing them.

notwaldorf commented 9 years ago

I think that's only true of iron-input. The only elements that work in a native form are paper-inputs, because their built on top of a regular input element. This isn't true of any other element, which is why we have created iron-form -- it's an extension of the native form, that also tracks custom elements to submit them.

hobberwickey commented 9 years ago

It should mention in the docs then that an iron-autogrow-text area and anything else isn't meant to be used inside a form element. It is currently pretty misleading.

More to the point though you could avoid the double submit quite simply by checking the items in the iron-form's serialize method's this.elements loop against the values in this._customElements and simply skipping the ones that are present. Then you can have custom elements that work with either an iron-form for a standard form which seems like the preferred behavior.

jab commented 8 years ago

Hit this myself and just wanted to +1 the suggestion to document the current behavior (and happy to send a PR if you like), but also ask if there's actually any chance of supporting both native forms and iron-forms, either via @hobberwickey's suggestion or otherwise. Acknowledging that custom elements in general don't have to work with native forms, nonetheless it'd be cool for paper-textarea to be consistent with paper-input in this way, since they're found right alongside one another and are morally equivalent.

jab commented 8 years ago

Hey @notwaldorf, would you accept a PR that implemented @hobberwickey's proposal?

Happy 2016!

notwaldorf commented 8 years ago

@jab a PR to iron-form? Yeah, that would be great!

jab commented 8 years ago

@notwaldorf Both a PR here to bind an iron-autogrow-textarea's name to its contained native textarea's, along with an accompanying PR to iron-form so that it doesn't count it twice?

notwaldorf commented 8 years ago

@jab Sure, I'd prefer if we got the iron-form one out of the way first, since that's the slightly more complicated one. Once that works, a PR here would be an easy merge

jab commented 8 years ago

@notwaldorf Great! @hobberwickey, are you still interested in submitting the patch you proposed?

hobberwickey commented 8 years ago

Sure, but I won't be able to until later tonight.

jab commented 8 years ago

Sweet, thanks!

jab commented 8 years ago

Hi @hobberwickey, still interested?

hobberwickey commented 8 years ago

Oh, totally spaced on this. Unfortunately, I'm on vacation until Feb 4th and left my computer at home. If someone wants to do it beforehand have at it, otherwise I'll try to remember when I get back. Sorry about the delay. On Jan 18, 2016 4:42 PM, "jab" notifications@github.com wrote:

Hi @hobberwickey https://github.com/hobberwickey, still interested?

— Reply to this email directly or view it on GitHub https://github.com/PolymerElements/iron-autogrow-textarea/issues/33#issuecomment-172648400 .

jab commented 8 years ago

Hey @hobberwickey, still want to take a crack at this?

hobberwickey commented 8 years ago

I created and issue (#106) for the iron-form change and submitted a pull request for the fix. However, I'm not sure my fix is ideal. Basically I check each custom element for a child element of the same name, if found I exclude the children from the submission and only use the custom element's value.

jab commented 8 years ago

Awesome @notwaldorf! Looks like this has been released already too. Thanks for the great work! :clap: