-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
Finished Paper Form Component #408
Finished Paper Form Component #408
Conversation
Should I consider this PR or #406 ? |
@miguelcobain Both of them. Multiple input validation in a form setting wasn't possible without the fix to inputs in #406. I first had to fix the inputs to not send separate isInvalid calls for both 'NULL' and 'TRUE' values. It was effectively double registering the invalid state of the input. #406 fixes that and this is the form component. |
Maybe we should have |
…o display all errors on submit instead
@@ -4,7 +4,7 @@ export default Ember.Component.extend({ | |||
tagName: '', | |||
classNames: [], | |||
attributeBindings: ['style'], | |||
style: "width:100%", | |||
style: 'width:100%', | |||
numberOfInvalids: 0, | |||
isValid: Ember.computed('numberOfInvalids', function() { | |||
return this.get('numberOfInvalids') === 0 ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return condition ? true : false;
is equivalent to return condition;
isValid: Ember.computed('numberOfInvalids', function() { | ||
return this.get('numberOfInvalids') === 0; | ||
}), | ||
isInvalid: Ember.computed('isValid', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destructure computed
can't you work around the |
@miguelcobain No because the value will never change in the parent component. The form is never going to set isTouched = true. So oldAttrs will always = newAttrs and will never execute. Unless I call a this.set('isTouched', true) then this.set('isTouched', false) which is more hacky than this solution. The tests fail with that proposed solution (unless I do the true to false hack). |
Can you edit this twiddle to reproduce that problem? |
How do I reproduce? |
@miguelcobain It didn't save for whatever reason. This is the right one: https://ember-twiddle.com/d7bc618f48a24a89e1bd9411c0d49050/91f4de4c453bcbe8650134d9d72c026ead80cf45?openFiles=controllers.application.js%2C 1.) Toggle controller. |
…sTouched to incrementCounter)
isValid: computed('childComponents.@each.isInvalid', function() { | ||
return !this.get('childComponents').isAny('isInvalid'); | ||
}), | ||
isInvalid: computed('isValid', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use computed.not
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
isValid: computed.not('childComponents.@each.isInvalid', function() { | ||
return this.get('childComponents').isAny('isInvalid'); | ||
}), | ||
isInvalid: computed.not('isValid', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read docs on computed.not. it doesn't take a callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that. I was in a rush out the door. I'll fix it when I get back.
If I want to use a custom paper-input component, is there an easy way to plug that in here? |
|
@dustinfarris: I agree. Any component yielded should be created from an attribute. Contextual components tightly couple. 👎 |
@DanChadwick The paper-input is an attribute of the contextual component because it's the most common input yielded in the form. It's impossible to take into account all possibilities in the contextual component (which I think is what you're saying), but you can make any paper-input based component a part of the form by adding |
@shoxter thanks for that example. what if i'm using an intermediary component that proxies to paper-input? e.g. my usage here adopted-ember-addons/ember-changeset#59 (comment) do i pass parentComponent down the chain? or just to the first component? is this officially supported? |
@dustinfarris No problem. The reason
Make sense? PS: Please note that the only reason |
@shoxter i think so, i'm just wondering how this will work with an intermediary component (i guess i'll find out soon enough!) e.g. my-route.hbs{{#paper-form as |form|}}
{{x-paper-input parentComponent=form}}
{{/paper-form}} x-paper-input.hbs{{paper-input parentComponent=parentComponent}} |
@dustinfarris x-paper-input extends paper-input? Edit: i see it doesn't. If it did, there is a way to make this work without contextual components. |
@dustinfarris should be fixed with 35d457f |
Usage like this:
Different Options:
The form looks at all the form.inputs with input constraints for invalidity.
Please post any questions. We can create a page on the dummy app to cover the documentation for this component once we cover any questions that should be included.