validation - Prevent removing field in json if field is empty and field is required angularjs -
i wondering if theres way prevent removing field in json.
for example have form:
<form name="frmsample"> <input type="text" required ng-model="user.firstname" /> <input type="text" ng-model="user.lastname" /> </form>
so if field not empty object {"firstname":"not empty","lastname":"not empty"} need make when empty: {"firstname":"","lastname":""} if required, not {"lastname":""}
is posible?
thanks
if understand question correctly, set values in controller this:
angular.module('myapp') .controller('myctrl', function ($scope) { // ... $scope.user = { firstname: '', lastname: '', }; // ... });
incidentally, it's required
attribute on user.firstname
input field that's causing firstname
property become undefined
. if remove required
attribute, problem goes away:
<form name="frmsample"> <input type="text" ng-model="user.firstname" /> <input type="text" ng-model="user.lastname" /> </form>
Comments
Post a Comment