1
1
/*!
2
2
* 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
4
5
* @license MIT
5
6
* Copyright (c) 2016 JSON Schema Form
6
7
*/
@@ -322,6 +323,33 @@ return /******/ (function(modules) { // webpackBootstrap
322
323
var childFrag = args . build ( args . form . items , args . path + '.items' , state ) ;
323
324
items . appendChild ( childFrag ) ;
324
325
}
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
+ } ;
325
353
}
326
354
} ;
327
355
this . builders = builders ;
@@ -372,7 +400,7 @@ return /******/ (function(modules) { // webpackBootstrap
372
400
// Reset arrayCompatFlag, it's only valid for direct children of the array.
373
401
state . arrayCompatFlag = false ;
374
402
375
- // TODO: Create a couple fo testcases, small and large and
403
+ // TODO: Create a couple of testcases, small and large and
376
404
// measure optmization. A good start is probably a
377
405
// cache of DOM nodes for a particular template
378
406
// that can be cloned instead of using innerHTML
@@ -530,8 +558,8 @@ return /******/ (function(modules) { // webpackBootstrap
530
558
sfSchema . evalInParentScope ( form . onClick , { '$event' : $event , form : form } ) ;
531
559
} else {
532
560
scope . $eval ( form . onClick , { '$event' : $event , form : form } ) ;
533
- }
534
- }
561
+ } ;
562
+ } ;
535
563
} ;
536
564
537
565
/**
@@ -658,11 +686,19 @@ return /******/ (function(modules) { // webpackBootstrap
658
686
// Where there is a key there is probably a ngModel
659
687
if ( form . key ) {
660
688
// 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 ;
662
692
if ( validationMessage === true || validationMessage === false ) {
663
693
validity = validationMessage ;
664
694
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
+ } ;
666
702
667
703
if ( scope . ngModel && error ) {
668
704
if ( scope . ngModel . $setDirty ) {
@@ -671,7 +707,7 @@ return /******/ (function(modules) { // webpackBootstrap
671
707
// FIXME: Check that this actually works on 1.2
672
708
scope . ngModel . $dirty = true ;
673
709
scope . ngModel . $pristine = false ;
674
- }
710
+ } ;
675
711
676
712
// Set the new validation message if one is supplied
677
713
// Does not work when validationMessage is just a string.
@@ -685,6 +721,9 @@ return /******/ (function(modules) { // webpackBootstrap
685
721
scope . ngModel . $setValidity ( error , validity === true ) ;
686
722
687
723
if ( validity === true ) {
724
+ // Re-trigger model validator, that model itself would be re-validated
725
+ scope . ngModel . $validate ( ) ;
726
+
688
727
// Setting or removing a validity can change the field to believe its valid
689
728
// but its not. So lets trigger its validation as well.
690
729
scope . $broadcast ( 'schemaFormValidate' ) ;
@@ -2594,6 +2633,7 @@ return /******/ (function(modules) { // webpackBootstrap
2594
2633
/**
2595
2634
* Evaluate an expression, i.e. scope.$eval
2596
2635
* but do it in sfSchemas parent scope sf-schema directive is used
2636
+ *
2597
2637
* @param {string } expression
2598
2638
* @param {Object } locals (optional)
2599
2639
* @return {Any } the result of the expression
@@ -2681,11 +2721,19 @@ return /******/ (function(modules) { // webpackBootstrap
2681
2721
// Where there is a key there is probably a ngModel
2682
2722
if ( form . key ) {
2683
2723
// 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 ;
2685
2727
if ( validationMessage === true || validationMessage === false ) {
2686
2728
validity = validationMessage ;
2687
2729
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
+ } ;
2689
2737
2690
2738
if ( scope . ngModel && error ) {
2691
2739
if ( scope . ngModel . $setDirty ) {
@@ -2708,6 +2756,9 @@ return /******/ (function(modules) { // webpackBootstrap
2708
2756
scope . ngModel . $setValidity ( error , validity === true ) ;
2709
2757
2710
2758
if ( validity === true ) {
2759
+ // Re-trigger model validator, that model itself would be re-validated
2760
+ scope . ngModel . $validate ( ) ;
2761
+
2711
2762
// Setting or removing a validity can change the field to believe its valid
2712
2763
// but its not. So lets trigger its validation as well.
2713
2764
scope . $broadcast ( 'schemaFormValidate' ) ;
@@ -3299,7 +3350,7 @@ return /******/ (function(modules) { // webpackBootstrap
3299
3350
// part of the form or schema is chnaged without it being a new instance.
3300
3351
scope . $on ( 'schemaFormRedraw' , function ( ) {
3301
3352
var schema = scope . schema ;
3302
- var form = scope . initialForm || [ '*' ] ;
3353
+ var form = scope . initialForm ? _angular2 . default . copy ( scope . initialForm ) : [ '*' ] ;
3303
3354
if ( schema ) {
3304
3355
render ( schema , form ) ;
3305
3356
}
@@ -3456,7 +3507,12 @@ return /******/ (function(modules) { // webpackBootstrap
3456
3507
var schema = form . schema ;
3457
3508
3458
3509
// 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
+ }
3460
3516
3461
3517
// Special case: arrays
3462
3518
// TODO: Can this be generalized in a way that works consistently?
@@ -3509,7 +3565,9 @@ return /******/ (function(modules) { // webpackBootstrap
3509
3565
} ) ;
3510
3566
3511
3567
// 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
+ } ) ;
3513
3571
3514
3572
scope . schemaError = function ( ) {
3515
3573
return error ;
0 commit comments