@workInProgress @ngdoc overview @name Cookbook: Advanced Form @description Here we extend the basic form example to include common features such as reverting, dirty state detection, and preventing invalid form submission.





,

[ add ]
[ X ]

Debug View:
form={{form}}
   master={{master}}
it('should enable save button', function() { expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy(); input('form.name').enter(''); expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy(); input('form.name').enter('change'); expect(element(':button:contains(Save)').attr('disabled')).toBeFalsy(); element(':button:contains(Save)').click(); expect(element(':button:contains(Save)').attr('disabled')).toBeTruthy(); }); it('should enable cancel button', function() { expect(element(':button:contains(Cancel)').attr('disabled')).toBeTruthy(); input('form.name').enter('change'); expect(element(':button:contains(Cancel)').attr('disabled')).toBeFalsy(); element(':button:contains(Cancel)').click(); expect(element(':button:contains(Cancel)').attr('disabled')).toBeTruthy(); expect(element(':input[ng\\:model="form.name"]').val()).toEqual('John Smith'); });
#Things to notice * Cancel & save buttons are only enabled if the form is dirty — there is something to cancel or save. * Save button is only enabled if there are no validation errors on the form. * Cancel reverts the form changes back to original state. * Save updates the internal model of the form. * Debug view shows the two models. One presented to the user form and the other being the pristine copy master.