What's a good pattern for submitting and validating forms using AngularJS? -


say i've got model kitty 2 required fields, name , favoritesnack. want let people edit kitties in view form looks like:

edit kitty name: [______________] favorite snack: [__________________] [submit] 

i'm stuck -- boring days of , post seemed easier. what's pattern setting angularjs? specifically,

  • how should set urls , methods? ngresource automatically? i'm guessing,
    • get /kitties - list kitties
    • get /kitties/:id - single kitten
    • post /kitties - create new kitty
    • put /kitties/:id - update kitty
    • delete /kitties/:id - delete kitty
  • on submit, should validate model client-side or server-side?
  • if server-side, how handle non-200 responses rest api i've hooked model to?
  • how should propagate errors user?
  • can validate-as-you-type?

please forgive me if i've missed obvious.

  • how should set urls , methods? ngresource automatically?

yes does, , yes should use ngresource.

  • on submit, should validate model client-side or server-side?

you should validate sent server on server, whether client-side validation or not. in angular, however, don't need validation on submit, validation can happen type (your last question)

  • if server-side, how handle non-200 responses rest api i've hooked model to?

you can handle them in error argument of ngresource methods. see returns section in documentation.

  • how should propagate errors user?

do angular way , set property on model in event of error. property should rendered somewhere on ui. if code right, can pretty guarantee using application right way have seen client-side errors, wouldn't put effort in field-specific errors server.

  • can validate-as-you-type?

yes, using of input attributes.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -