AngularJS form validation via interpolated pattern

296 Views Asked by At

I'm trying to make a simple input that validates only by matching some data in scope, literally:

<ng-form name="fooForm">
  <input required
         pattern="/{{foo}}/"
         ng-model="dummy"
         name="shouldBeFoo" />
  <button ng-class="{disabled: fooForm.shouldBeFoo.$invalid}">
    Run Foo
  </button>
</ng-form>

However, running this code shows that the $invalid attribute doesn't account for the interpolated pattern. Is there a programmatic way of setting the input's validation to equal foo, precisely? Maybe some function predicate?

1

There are 1 best solutions below

0
On BEST ANSWER

See ng-pattern to specify a pattern using an expression: https://docs.angularjs.org/api/ng/directive/input