forms - Emberjs live serverside validation -


i've managed input going server, , server responding if input valid, or returning error object if not.

i'm not sure how use returned error object something. there many examples around internet of how loop through error object , display message isn't i'm after.

i have form component has bunch of fields like:

{{input type="text" value=account.twitterid class="input" focus-out="validateinput"}} 

and validateinput in component looks like

validateinput() {   let account = get(this, 'account');    account.save().then(() => {     console.log('success!'); // add class input field   }).catch((adaptererror) => {     console.log(account.get('errors')); // add different class input field     console.log(adaptererror);   }); }, 

as mentioned above, triggers , either returns successful or error message

but how take result , use add classes class key of input field?

i did attempt following

  haserror: false,    actions: {    validateinput() {     let account = get(this, 'account');      account.save().then(() => {       set(this, 'haserror', false);     }).catch((adaptererror) => {       set(this, 'haserror', true);     });   }, 

}

and if statement in front, kind of worked didn't re-trigger if user changes input second time.

am supposed use computed property this? if how 1 look?

your plan should work. i've created ember twiddle can use reference. tweaked model little allow random success / failure promises coming save() method, rest pretty identical posted. open console while tabbing out of twiddle see result of promise being returned. use template conditional recommended hide/show feedback user.

https://ember-twiddle.com/3398d28381a4c0afb71cb5d59f271e36

let me know if have questions between implementation , have in twiddle. ✌🏽


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -