Following this bit of code:
<label class="checkbox-label">
<input name="radio1" type="radio"
ng-model="myModel.radio"
required ng-required="true"
value="1">
</label>
<label class="checkbox-label">
<input name="radio1" type="radio"
ng-model="myModel.radio"
required ng-required="true"
value="2">
</label>
<input type="number" name="result" class="form-control input-sm" ng-model="myModel.result"
required ng-required="true" ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/" step="0.1" min="0" max="100">
i need to set the ng-pattern
& step
to accept one decimal place (0.1) or two decimal places (0.01) based on the radio1
selection
Anyone has an idea how to approach this?
UPDATE I have created a directive to do this, but validation is not triggered after changing the pattern (Angular 1.2)
app.directive('stepChange', function () {
return {
link: function link(scope, element, attr) {
element.bind('change', function () {
var el = angular.element(attr['target']);
el.attr('step', attr['step']);
el.attr('pattern', attr['pattern']);
el.val(attr['val']);
el.trigger();
});
}
}
});