1

I'm trying to make a form that can contain complex "fieldtypes". ie. A group of fields that work together to manipulate the value of a single field.

Each of these fieldtypes contains a single field that will hold the actual "value" of the field.

The fields containing the real data will have ng-model="" attributes attached to them. The PublishController will be monitoring these fields. If there are fields without an ng-model on them, it doesn't care about it.

Is it possible to make a form only consider itself dirty/pristine by the fields with ng-model on them?

I don't mind having to put a class/attribute on all the fields I want it to watch specifically, if thats an option.

Here's an example of the code:

<div ng-controller="PublishController">

  <form name="publishForm" ng-submit="save()">

    <div class="fieldtype">
      <!-- there might be a bunch of form elements in here that a user can manipulate to alter the value that the PublishController is concerned with -->
      <input class="helper-field-1" />
      <input class="helper-field-2" />

      <!-- then the inputs above will perform their own logic, and output their value to this field, which the form *is* concerned with -->
      <input type="hidden" name="myfield" ng-model="data.myfield" />
    </div>

    <div class="fieldtype">...</div>
    <div class="fieldtype">...</div>

    <!-- one of the goals of this is to only show the submit button when the *actual* values have been modified, not the helper fields -->
    <button ng-disabled="publishForm.$pristine">Save</button>

  </form>

</div>

Is what I'm describing possible?

Thanks!

Jason Varga
  • 1,949
  • 2
  • 21
  • 29

0 Answers0