Skip to content

Commit b597721

Browse files
committed
Adds numeric min/max to builder service and bump alpha version
1 parent dd3c197 commit b597721

File tree

6 files changed

+145
-20
lines changed

6 files changed

+145
-20
lines changed

dist/bootstrap-decorator.js

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/schema-form.js

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*!
22
* angular-schema-form
3-
* @version 1.0.0-alpha.1
3+
* @version 1.0.0-alpha.2
4+
* @link https://github.com/json-schema-form/angular-schema-form
45
* @license MIT
56
* Copyright (c) 2016 JSON Schema Form
67
*/
@@ -322,6 +323,33 @@ return /******/ (function(modules) { // webpackBootstrap
322323
var childFrag = args.build(args.form.items, args.path + '.items', state);
323324
items.appendChild(childFrag);
324325
}
326+
},
327+
numeric: function numeric(args) {
328+
var inputFrag = args.fieldFrag.querySelector('input');
329+
var maximum = args.form.maximum || false;
330+
var exclusiveMaximum = args.form.exclusiveMaximum || false;
331+
var minimum = args.form.minimum || false;
332+
var exclusiveMinimum = args.form.exclusiveMinimum || false;
333+
var multipleOf = args.form.multipleOf || false;
334+
if (inputFrag) {
335+
if (multipleOf !== false) {
336+
inputFrag.setAttribute('step', multipleOf);
337+
};
338+
339+
if (maximum !== false) {
340+
if (exclusiveMaximum !== false && multipleOf !== false) {
341+
maximum = maximum - multipleOf;
342+
};
343+
inputFrag.setAttribute('max', maximum);
344+
};
345+
346+
if (minimum !== false) {
347+
if (exclusiveMinimum !== false && multipleOf !== false) {
348+
minimum = minimum + multipleOf;
349+
};
350+
inputFrag.setAttribute('min', minimum);
351+
};
352+
};
325353
}
326354
};
327355
this.builders = builders;
@@ -372,7 +400,7 @@ return /******/ (function(modules) { // webpackBootstrap
372400
// Reset arrayCompatFlag, it's only valid for direct children of the array.
373401
state.arrayCompatFlag = false;
374402

375-
// TODO: Create a couple fo testcases, small and large and
403+
// TODO: Create a couple of testcases, small and large and
376404
// measure optmization. A good start is probably a
377405
// cache of DOM nodes for a particular template
378406
// that can be cloned instead of using innerHTML
@@ -530,8 +558,8 @@ return /******/ (function(modules) { // webpackBootstrap
530558
sfSchema.evalInParentScope(form.onClick, { '$event': $event, form: form });
531559
} else {
532560
scope.$eval(form.onClick, { '$event': $event, form: form });
533-
}
534-
}
561+
};
562+
};
535563
};
536564

537565
/**
@@ -658,11 +686,19 @@ return /******/ (function(modules) { // webpackBootstrap
658686
// Where there is a key there is probably a ngModel
659687
if (form.key) {
660688
// It looks better with dot notation.
661-
scope.$on('schemaForm.error.' + form.key.join('.'), function (event, error, validationMessage, validity) {
689+
scope.$on('schemaForm.error.' + form.key.join('.'), function (event, error, validationMessage, validity, formName) {
690+
// validationMessage and validity are mutually exclusive
691+
formName = validity;
662692
if (validationMessage === true || validationMessage === false) {
663693
validity = validationMessage;
664694
validationMessage = undefined;
665-
}
695+
};
696+
697+
// If we have specified a form name, and this model is not within
698+
// that form, then leave things be.
699+
if (formName != undefined && scope.ngModel.$$parentForm.$name !== formName) {
700+
return;
701+
};
666702

667703
if (scope.ngModel && error) {
668704
if (scope.ngModel.$setDirty) {
@@ -671,7 +707,7 @@ return /******/ (function(modules) { // webpackBootstrap
671707
// FIXME: Check that this actually works on 1.2
672708
scope.ngModel.$dirty = true;
673709
scope.ngModel.$pristine = false;
674-
}
710+
};
675711

676712
// Set the new validation message if one is supplied
677713
// Does not work when validationMessage is just a string.
@@ -685,6 +721,9 @@ return /******/ (function(modules) { // webpackBootstrap
685721
scope.ngModel.$setValidity(error, validity === true);
686722

687723
if (validity === true) {
724+
// Re-trigger model validator, that model itself would be re-validated
725+
scope.ngModel.$validate();
726+
688727
// Setting or removing a validity can change the field to believe its valid
689728
// but its not. So lets trigger its validation as well.
690729
scope.$broadcast('schemaFormValidate');
@@ -2594,6 +2633,7 @@ return /******/ (function(modules) { // webpackBootstrap
25942633
/**
25952634
* Evaluate an expression, i.e. scope.$eval
25962635
* but do it in sfSchemas parent scope sf-schema directive is used
2636+
*
25972637
* @param {string} expression
25982638
* @param {Object} locals (optional)
25992639
* @return {Any} the result of the expression
@@ -2681,11 +2721,19 @@ return /******/ (function(modules) { // webpackBootstrap
26812721
// Where there is a key there is probably a ngModel
26822722
if (form.key) {
26832723
// It looks better with dot notation.
2684-
scope.$on('schemaForm.error.' + form.key.join('.'), function (event, error, validationMessage, validity) {
2724+
scope.$on('schemaForm.error.' + form.key.join('.'), function (event, error, validationMessage, validity, formName) {
2725+
// validationMessage and validity are mutually exclusive
2726+
formName = validity;
26852727
if (validationMessage === true || validationMessage === false) {
26862728
validity = validationMessage;
26872729
validationMessage = undefined;
2688-
}
2730+
};
2731+
2732+
// If we have specified a form name, and this model is not within
2733+
// that form, then leave things be.
2734+
if (formName != undefined && scope.ngModel.$$parentForm.$name !== formName) {
2735+
return;
2736+
};
26892737

26902738
if (scope.ngModel && error) {
26912739
if (scope.ngModel.$setDirty) {
@@ -2708,6 +2756,9 @@ return /******/ (function(modules) { // webpackBootstrap
27082756
scope.ngModel.$setValidity(error, validity === true);
27092757

27102758
if (validity === true) {
2759+
// Re-trigger model validator, that model itself would be re-validated
2760+
scope.ngModel.$validate();
2761+
27112762
// Setting or removing a validity can change the field to believe its valid
27122763
// but its not. So lets trigger its validation as well.
27132764
scope.$broadcast('schemaFormValidate');
@@ -3299,7 +3350,7 @@ return /******/ (function(modules) { // webpackBootstrap
32993350
// part of the form or schema is chnaged without it being a new instance.
33003351
scope.$on('schemaFormRedraw', function () {
33013352
var schema = scope.schema;
3302-
var form = scope.initialForm || ['*'];
3353+
var form = scope.initialForm ? _angular2.default.copy(scope.initialForm) : ['*'];
33033354
if (schema) {
33043355
render(schema, form);
33053356
}
@@ -3456,7 +3507,12 @@ return /******/ (function(modules) { // webpackBootstrap
34563507
var schema = form.schema;
34573508

34583509
// A bit ugly but useful.
3459-
scope.validateField = function () {
3510+
scope.validateField = function (formName) {
3511+
// If we have specified a form name, and this model is not within
3512+
// that form, then leave things be.
3513+
if (formName != undefined && ngModel.$$parentForm.$name !== formName) {
3514+
return;
3515+
}
34603516

34613517
// Special case: arrays
34623518
// TODO: Can this be generalized in a way that works consistently?
@@ -3509,7 +3565,9 @@ return /******/ (function(modules) { // webpackBootstrap
35093565
});
35103566

35113567
// Listen to an event so we can validate the input on request
3512-
scope.$on('schemaFormValidate', scope.validateField);
3568+
scope.$on('schemaFormValidate', function (event, formName) {
3569+
scope.validateField(formName);
3570+
});
35133571

35143572
scope.schemaError = function () {
35153573
return error;

0 commit comments

Comments
 (0)