I use Angular JS for all form management now. Data for inputs are stored to their associated ngModel
, which can be dealt with in the $scope
of the controller
.
So I have form setups like this:
<form name="addJob" novalidate data-ng-submit="addJob.$valid && addJob(job)">
<input type="text" placeholder="Job Title" data-ng-model="job.title" required />
<textarea placeholder="Brief" data-ng-model="job.brief"></textarea>
<button type="submit" data-ng-disabled="addJob.$invalid">Add Job</button>
</form>
This works absolutely fine in all major browsers (except I haven't tested IE). You'll notice I haven't included name attributes on the input or textarea. Do I need them for any reason? I've read the following before:
Note: Only form elements with a name attribute will have their values passed when submitting a form.
But my data is passed absolutely fine because it's bound to the ngModel
. Was is the correct method - include or not include name attributes?