javascript - Is it possible to validate a textfield containing name as objectVO.fieldname using AngularJS -
is there way validate textfield
name contains objectvo . fieldname
using angularjs?
<form name="form" ng-submit="submitform($event)" novalidate() > <input type="text" name="objectvo.fieldname" ng-model="fieldname" required /> <span class="error" ng-show="form.objectvo.fieldname.$invalid" > </form>
i using value object
pattern , angularjs understands plain character fieldname of input fields.
how display error in ng-show?
ng-show="form.objectvo.fieldname.$invalid" not valid statement. correct way?
i have researched lot, didn't find useful content. please help!
you need use "array" notation accessing object's properties:
ng-show="form['object.fieldname'].$invalid"
see, also, short demo.
in javascript obj.someprop
shorthand (and equivalent to) obj['someprop']
.
useful accessing object's property when don't know name @ "compile-time", know @ "run-time" (i.e. know there variable holding name of property want access):
function accesssomeproperty(object, propertyname) { return object[propertyname]; }
e.g.
propname = 'test'; accesssomeproperty(obj, propname); // returns: obj[propname] // === obj['test'] // === obj.test // benefit 'test' // specified dynamically
Comments
Post a Comment