Skip to content
This repository has been archived by the owner on Apr 30, 2018. It is now read-only.

Commit

Permalink
v8.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
formly-bot committed Jul 26, 2016
2 parents 56ecbf5 + f2d7bc9 commit c01a4de
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
18 changes: 12 additions & 6 deletions dist/formly.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* angular-formly JavaScript Library v8.2.1
* angular-formly JavaScript Library v8.3.0
*
* @license MIT (http://license.angular-formly.com)
*
Expand Down Expand Up @@ -157,7 +157,7 @@ return /******/ (function(modules) { // webpackBootstrap

ngModule.constant('formlyApiCheck', _providersFormlyApiCheck2['default']);
ngModule.constant('formlyErrorAndWarningsUrlPrefix', _otherDocsBaseUrl2['default']);
ngModule.constant('formlyVersion', ("8.2.1")); // <-- webpack variable
ngModule.constant('formlyVersion', ("8.3.0")); // <-- webpack variable

ngModule.provider('formlyUsability', _providersFormlyUsability2['default']);
ngModule.provider('formlyConfig', _providersFormlyConfig2['default']);
Expand Down Expand Up @@ -435,7 +435,7 @@ return /******/ (function(modules) { // webpackBootstrap
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = "https://github.com/formly-js/angular-formly/blob/" + ("8.2.1") + "/other/ERRORS_AND_WARNINGS.md#";
exports["default"] = "https://github.com/formly-js/angular-formly/blob/" + ("8.3.0") + "/other/ERRORS_AND_WARNINGS.md#";
module.exports = exports["default"];

/***/ },
Expand Down Expand Up @@ -1273,18 +1273,24 @@ return /******/ (function(modules) { // webpackBootstrap

// function definitions
function runExpressions() {
var deferred = $q.defer();
// must run on next tick to make sure that the current value is correct.
return $timeout(function runExpressionsOnNextTick() {
$timeout(function runExpressionsOnNextTick() {
var promises = [];
var field = $scope.options;
var currentValue = valueGetterSetter();
_angularFix2['default'].forEach(field.expressionProperties, function runExpression(expression, prop) {
var setter = $parse(prop).assign;
var promise = $q.when(formlyUtil.formlyEval($scope, expression, currentValue, currentValue));
promise.then(function setFieldValue(value) {
var promise = $q.when(formlyUtil.formlyEval($scope, expression, currentValue, currentValue)).then(function setFieldValue(value) {
setter(field, value);
});
promises.push(promise);
});
$q.all(promises).then(function () {
deferred.resolve();
});
}, 0, false);
return deferred.promise;
}

function watchExpressions() {
Expand Down
6 changes: 3 additions & 3 deletions dist/formly.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/formly.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-formly",
"version": "8.2.1",
"version": "8.3.0",
"author": "Astrism <astrisms@gmail.com>",
"contributors": [
"Astrism <astrisms@gmail.com>",
Expand Down
15 changes: 11 additions & 4 deletions src/directives/formly-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,25 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo

// function definitions
function runExpressions() {
const deferred = $q.defer()
// must run on next tick to make sure that the current value is correct.
return $timeout(function runExpressionsOnNextTick() {
$timeout(function runExpressionsOnNextTick() {
const promises = []
const field = $scope.options
const currentValue = valueGetterSetter()
angular.forEach(field.expressionProperties, function runExpression(expression, prop) {
const setter = $parse(prop).assign
const promise = $q.when(formlyUtil.formlyEval($scope, expression, currentValue, currentValue))
promise.then(function setFieldValue(value) {
setter(field, value)
})
.then(function setFieldValue(value) {
setter(field, value)
})
promises.push(promise)
})
$q.all(promises).then(function() {
deferred.resolve()
})
}, 0, false)
return deferred.promise
}

function watchExpressions() {
Expand Down
43 changes: 43 additions & 0 deletions src/directives/formly-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,4 +1314,47 @@ describe('formly-form', () => {
})
})
})
describe('extras', () => {
describe('validateOnModelChange', () => {
it('should run validators after expressions are set', () => {
let inputs, invalidInputs, el

scope.model = {
foo: null,
bar: 123,
}

scope.fields = [
{template: input, key: 'foo', extras: {validateOnModelChange: true}},
{template: input, key: 'bar', templateOptions: {type: 'number'}},
]
// First Field isn't valid when second field is 1
scope.fields[0].expressionProperties = {
'templateOptions.isValid': 'model.bar !== 1',
}
// validator to use isValid attribute
scope.fields[0].validators = {isValid: {expression: (viewValue, modelValue, fieldScope) => {
return fieldScope.to.isValid
}}}

el = compileAndDigest()

// Input state before
inputs = el[0].querySelectorAll('input')
invalidInputs = el[0].querySelectorAll('input.ng-invalid')
expect(inputs.length).to.equal(2)
expect(invalidInputs.length).to.equal(0)

// Enter '1' into second field
angular.element(inputs[1]).val(1).triggerHandler('change')
$timeout.flush()

// Input state after
inputs = el[0].querySelectorAll('input')
invalidInputs = el[0].querySelectorAll('input.ng-invalid')
expect(inputs.length).to.equal(2)
expect(invalidInputs.length).to.equal(1)
})
})
})
})

0 comments on commit c01a4de

Please sign in to comment.