File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
packages/components/field/src/js Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -226,7 +226,9 @@ export default class FieldController {
226226 const attributes = VALIDATION_PARAMETERS [ validationName ] ;
227227 attributes . forEach ( ( attributeName ) => {
228228 if ( hasAttributeValue ( controlElement , attributeName ) ) {
229- validationParameters [ validationName ] = getAttribute ( controlElement , attributeName ) ;
229+ Object . defineProperty ( validationParameters , validationName , {
230+ get : ( ) => getAttribute ( controlElement , attributeName ) ,
231+ } ) ;
230232 }
231233 } ) ;
232234 } ) ;
Original file line number Diff line number Diff line change @@ -643,6 +643,44 @@ describe('ouiField', () => {
643643 expect ( controller . getErrorMessage ( 'minlength' ) ) . toContain ( messageMinlength ) ;
644644 } ) ;
645645
646+ it ( 'should give a dynamic message containing parameters' , ( ) => {
647+ const minValue = 5 ;
648+ const element = TestUtils . compileTemplate ( `
649+ <form name="form">
650+ <oui-field label="{{'range'}}">
651+ <input type="number"
652+ class="oui-input"
653+ id="range_start"
654+ name="range_start"
655+ ng-model="$ctrl.rangeStart">
656+ <input type="number"
657+ class="oui-input"
658+ id="range_end"
659+ name="range_end"
660+ ng-min="$ctrl.rangeStart"
661+ ng-model="$ctrl.rangeEnd">
662+ </oui-field>
663+ </form>
664+ ` , {
665+ rangeStart : 0 ,
666+ rangeEnd : 0 ,
667+ } ) ;
668+
669+ const controller = getField ( element ) . controller ( 'ouiField' ) ;
670+
671+ $timeout . flush ( ) ;
672+
673+ const $rangeStartControl = getControl ( controller , 'range_start' ) ;
674+ $rangeStartControl . val ( minValue ) ;
675+ $rangeStartControl . triggerHandler ( 'input' ) ;
676+ $rangeStartControl . triggerHandler ( 'blur' ) ;
677+
678+ $timeout . flush ( ) ;
679+
680+ expect ( controller . getFirstError ( ) . min ) . toBeTruthy ( ) ;
681+ expect ( controller . getErrorMessage ( 'min' ) ) . toContain ( minValue ) ;
682+ } ) ;
683+
646684 it ( 'should show error on submit' , ( ) => {
647685 const element = TestUtils . compileTemplate ( `
648686 <form name="form" ng-submit="$ctrl.noop()">
You can’t perform that action at this time.
0 commit comments