Comments (15)
Hi @g8anusha,
could you please share some code (template and controller/component) that illustrates how you're submitting the form? - I haven't seen this issue before.
Thanks!
from ember-validated-form.
- I am not able to use ember-concurrency, by giving a task in the controller. It throws exception, and also the save button doesn't get disabled.
- Also, a new model is getting created in the validated-form, which doesn't affect the actual model created in the model hook of the route.
app/routes/home.js
model() {
return Ember.RSVP.hash({
homeModel: this.store.createRecord('homeModel', {});
});
}
app/controllers/home.js
export default Ember.Controller.extend({
HomeModelValidations,
actions: {
submit: task(function * (model) {
yield model.save();
}),
cancel(model) {
model.rollback(); // throws exception saying model.rollbackAttributes() is not a function
this.transitionToRoute('index');
},
mutatingGender(model, value) {
model.set('gender', this.store.peekRecord('gender', value));
console.log(this.get('model.homeModel.gender')); // displays undefined
}
}
});
app/templates/home.hbs
<div class='ml-grid'>
{{#validated-form model=(changeset model.homeModel HomeModelValidations) on-submit=(action 'submit') as |f|}}
<div>
{{f.input value='name' value='name'}}
{{#f.input value='occupation' name='occupation' as |fi|}}
{{#power-select
options=occupation
searchField='occupationName'
onchange=fi.update
required=true
selected=f.model.occupation as |o|}}
{{o.occupationName}}
{{/power-select}}
{{/f.input}}
{{#f.input value='gender' name='gender' on-update=(action 'mutatingGender' f.model) as |fi|}}
{{#each gender as |g|}}
<div class='radio'>
{{#one-way-radio
name = 'gender'
value=g.id
onchange=fi.setDirty
update=fi.update
required=true
option=g.id}}
{{/one-way-radio}}
{{g.genderName}}
</div>
{{/each}}
{{/f.input}}
{{f.submit label='Save'}}
<button {{action 'cancel' f.model}}> Cancel </button>
</div>
{{/validated-form}}
</div>
Please ignore the css parts for now.
Thanks in advance!
from ember-validated-form.
Hi @g8anusha, a quick hint concerning your first point: The ember-concurrency task is not an action, it should be a property:
export default Ember.Controller.extend({
HomeModelValidations,
submit: task(function * (model) {
yield model.save();
}),
// ...
I'll get back to you concerning your second poin later! 😄
from ember-validated-form.
Thanks @czosel, how do I use it in the template then??
from ember-validated-form.
Simply
(This should probably be documented in our README... )
from ember-validated-form.
I tried the above way, it now enters the method, but the submit button is not disabled.
Do I need to give disabled=true manually?? Even with that, its not working!
from ember-validated-form.
Hi @g8anusha,
You don't have to specify disabled=true
manually. Since I couldn't reproduce your issue I created a twiddle that shows a minimal working demo using ember-concurrency tasks.
I hope that'll help - if not, could you tweak the twiddle to reproduce the problem you're facing?
from ember-validated-form.
Thanks, I'll have a look at time.
meanwhile, can you give me a solution to the 2nd point I mentioned in the previous comments?
from ember-validated-form.
Hi @g8anusha,
Sorry, I totally forgot 😅
I wasn't able to reproduce your issue with rollback
. Please see this twiddle for a working demo.
As for the mutatingGender
part - the way you implemented this seems quite complex - why not just use a radioGroup
(see docs) for this?
from ember-validated-form.
Hi @czosel , rollback is solved now.
But, the save button doesn't get disabled. In the twiddle it shows to be disabled, but in the local dev env it isn't showing as disabled.
from ember-validated-form.
Hi @g8anusha,
I'm happy to hear rollback
is working for you now!
Concerning the disabled submit button, we'll need a reproduction to go forward. I'd suggest you try to simplify your local dev environment until it matches the twiddle. Another possibility is to set up a new ember app locally with a minimal example (like in the twiddle) and expand it to the more complex case you have currently. Either way, like this you should be able to find out what's introducing your issue.
You can also try to adapt the fiddle to match the dependency versions you have locally.
Good luck!
from ember-validated-form.
Hi @czosel,
I had misunderstood the usage of concurrency here using task. I was thinking that save will be disabled until all the fields are filled and valid. But, just now realised that it will be disabled until the save operation is finished. Sorry for that!
But, my question is right in a way. How do I disable the save button until all the fields are filled out?? Is there any way in ember-concurrency to achieve that?
from ember-validated-form.
Hi @g8anusha,
Ah, that explains the confusion 😄
Disabling the submit button is not officially supported because we believe it is not great for UX - it might leave people wondering why they can't submit the form. This is especially bad when not all form fields are dirty yet, because then they wouldn't even see any error messages.
I just played around with this a little and it turns out to be possible, though: see this fiddle
Let me know what you think! 😉
from ember-validated-form.
Hurray! It's working! Thank you :) Will get in touch again if I face any more difficulties. 💯 🥇
from ember-validated-form.
Awesome! 👍
from ember-validated-form.
Related Issues (20)
- Optional instead of required
- Dummy app is not loading HOT 1
- Configuration in config/environment.js not working? HOT 4
- TODO: Migrate from ember-i18n to ember-intl HOT 1
- Bootstrap classes not generating HOT 5
- queue is not a helper HOT 1
- Fails to build with embroider
- type=number additional properties HOT 1
- v1 version does not honor previous locale setting of ember-intl HOT 1
- Errors aren't being updated HOT 3
- Release v3.0.3? HOT 2
- Submit event missing event and sender parameters
- Documentation page unusable ("htmlsafe is not a function")
- Cleanup after embroider fixes HOT 1
- Docs are busted HOT 2
- Nested properties not validating (solved) HOT 1
- Help needed to use "on" modifier with <ValidatedInput /> HOT 2
- Adding custom inputs
- Embroider Support is broken HOT 1
- Master is incompatible with node < 18 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-validated-form.