@@ -2801,6 +2801,26 @@ describe('input', function() {
2801
2801
scope = $rootScope ;
2802
2802
} ) ;
2803
2803
2804
+ it ( 'should be treated as `input[text]` without the `ng-input-range` attribute' , function ( ) {
2805
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="age" />' ) ;
2806
+ var ngModel = inputElm . controller ( 'ngModel' ) ;
2807
+
2808
+ helper . changeInputValueTo ( 25 ) ;
2809
+
2810
+ expect ( scope . age ) . toBe ( '25' ) ;
2811
+ expect ( ngModel . $$parserName ) . toBeUndefined ( ) ;
2812
+ } ) ;
2813
+
2814
+ it ( 'should not be treated as `input[text]` with the `ng-input-range` attribute' , function ( ) {
2815
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="age" ng-input-range />' ) ;
2816
+ var ngModel = inputElm . controller ( 'ngModel' ) ;
2817
+
2818
+ helper . changeInputValueTo ( '25' ) ;
2819
+
2820
+ expect ( scope . age ) . toBe ( 25 ) ;
2821
+ expect ( ngModel . $$parserName ) . toBe ( 'number' ) ;
2822
+ } ) ;
2823
+
2804
2824
if ( supportsRange ) {
2805
2825
// This behavior only applies to browsers that implement the range input, which do not
2806
2826
// allow to set a non-number value and will set the value of the input to 50 even when you
@@ -2809,7 +2829,7 @@ describe('input', function() {
2809
2829
// sense if the input value is a string. These browsers will mark the input as invalid instead.
2810
2830
2811
2831
it ( 'should render as 50 if null' , function ( ) {
2812
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age" /> ') ;
2832
+ var inputElm = compileRangeInput ( ' ng-model="age"') ;
2813
2833
2814
2834
helper . changeInputValueTo ( '25' ) ;
2815
2835
expect ( scope . age ) . toBe ( 25 ) ;
@@ -2820,7 +2840,7 @@ describe('input', function() {
2820
2840
} ) ;
2821
2841
2822
2842
it ( 'should set model to 50 when no value specified and default min/max' , function ( ) {
2823
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age" /> ') ;
2843
+ var inputElm = compileRangeInput ( ' ng-model="age"') ;
2824
2844
2825
2845
expect ( inputElm . val ( ) ) . toBe ( '50' ) ;
2826
2846
@@ -2830,7 +2850,7 @@ describe('input', function() {
2830
2850
} ) ;
2831
2851
2832
2852
it ( 'should parse non-number values to 50 when default min/max' , function ( ) {
2833
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age" /> ') ;
2853
+ var inputElm = compileRangeInput ( ' ng-model="age"') ;
2834
2854
2835
2855
scope . $apply ( 'age = 10' ) ;
2836
2856
expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
@@ -2843,7 +2863,7 @@ describe('input', function() {
2843
2863
} else {
2844
2864
2845
2865
it ( 'should reset the model if view is invalid' , function ( ) {
2846
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age"/> ') ;
2866
+ var inputElm = compileRangeInput ( ' ng-model="age"') ;
2847
2867
2848
2868
scope . $apply ( 'age = 100' ) ;
2849
2869
expect ( inputElm . val ( ) ) . toBe ( '100' ) ;
@@ -2856,7 +2876,7 @@ describe('input', function() {
2856
2876
}
2857
2877
2858
2878
it ( 'should parse the input value to a Number' , function ( ) {
2859
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age" /> ') ;
2879
+ var inputElm = compileRangeInput ( ' ng-model="age"') ;
2860
2880
2861
2881
helper . changeInputValueTo ( '75' ) ;
2862
2882
expect ( scope . age ) . toBe ( 75 ) ;
@@ -2866,7 +2886,7 @@ describe('input', function() {
2866
2886
it ( 'should only invalidate the model if suffering from bad input when the data is parsed' , function ( ) {
2867
2887
scope . age = 60 ;
2868
2888
2869
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age" /> ', {
2889
+ var inputElm = compileRangeInput ( ' ng-model="age"', {
2870
2890
valid : false ,
2871
2891
badInput : true
2872
2892
} ) ;
@@ -2883,7 +2903,7 @@ describe('input', function() {
2883
2903
it ( 'should throw if the model value is not a number' , function ( ) {
2884
2904
expect ( function ( ) {
2885
2905
scope . value = 'one' ;
2886
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" /> ') ;
2906
+ var inputElm = compileRangeInput ( ' ng-model="value"') ;
2887
2907
} ) . toThrowMinErr ( 'ngModel' , 'numfmt' , 'Expected `one` to be a number' ) ;
2888
2908
} ) ;
2889
2909
@@ -2895,7 +2915,7 @@ describe('input', function() {
2895
2915
it ( 'should initialize correctly with non-default model and min value' , function ( ) {
2896
2916
scope . value = - 3 ;
2897
2917
scope . min = - 5 ;
2898
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" /> ') ;
2918
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" min="{{min}}"') ;
2899
2919
2900
2920
expect ( inputElm ) . toBeValid ( ) ;
2901
2921
expect ( inputElm . val ( ) ) . toBe ( '-3' ) ;
@@ -2905,7 +2925,7 @@ describe('input', function() {
2905
2925
2906
2926
// Browsers that implement range will never allow you to set the value < min values
2907
2927
it ( 'should adjust invalid input values' , function ( ) {
2908
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="10" /> ') ;
2928
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" min="10"') ;
2909
2929
2910
2930
helper . changeInputValueTo ( '5' ) ;
2911
2931
expect ( inputElm ) . toBeValid ( ) ;
@@ -2921,7 +2941,7 @@ describe('input', function() {
2921
2941
it ( 'should set the model to the min val if it is less than the min val' , function ( ) {
2922
2942
scope . value = - 10 ;
2923
2943
// Default min is 0
2924
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" /> ') ;
2944
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" min="{{min}}"') ;
2925
2945
2926
2946
expect ( inputElm ) . toBeValid ( ) ;
2927
2947
expect ( inputElm . val ( ) ) . toBe ( '0' ) ;
@@ -2936,7 +2956,7 @@ describe('input', function() {
2936
2956
2937
2957
it ( 'should adjust the element and model value when the min value changes on-the-fly' , function ( ) {
2938
2958
scope . min = 10 ;
2939
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" /> ') ;
2959
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" min="{{min}}"') ;
2940
2960
2941
2961
helper . changeInputValueTo ( '15' ) ;
2942
2962
expect ( inputElm ) . toBeValid ( ) ;
@@ -2970,7 +2990,7 @@ describe('input', function() {
2970
2990
// input[type=range] will become type=text in browsers that don't support it
2971
2991
2972
2992
it ( 'should validate if "range" is not implemented' , function ( ) {
2973
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="10" /> ') ;
2993
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" min="10"') ;
2974
2994
2975
2995
helper . changeInputValueTo ( '5' ) ;
2976
2996
expect ( inputElm ) . toBeInvalid ( ) ;
@@ -2985,7 +3005,7 @@ describe('input', function() {
2985
3005
2986
3006
it ( 'should not assume a min val of 0 if the min interpolates to a non-number' , function ( ) {
2987
3007
scope . value = - 10 ;
2988
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" /> ') ;
3008
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" min="{{min}}"') ;
2989
3009
2990
3010
expect ( inputElm ) . toBeValid ( ) ;
2991
3011
expect ( inputElm . val ( ) ) . toBe ( '-10' ) ;
@@ -3013,7 +3033,7 @@ describe('input', function() {
3013
3033
3014
3034
it ( 'should validate even if the min value changes on-the-fly' , function ( ) {
3015
3035
scope . min = 10 ;
3016
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" /> ') ;
3036
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" min="{{min}}"') ;
3017
3037
3018
3038
helper . changeInputValueTo ( '15' ) ;
3019
3039
expect ( inputElm ) . toBeValid ( ) ;
@@ -3054,7 +3074,7 @@ describe('input', function() {
3054
3074
it ( 'should initialize correctly with non-default model and max value' , function ( ) {
3055
3075
scope . value = 130 ;
3056
3076
scope . max = 150 ;
3057
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" /> ') ;
3077
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="{{max}}"') ;
3058
3078
3059
3079
expect ( inputElm ) . toBeValid ( ) ;
3060
3080
expect ( inputElm . val ( ) ) . toBe ( '130' ) ;
@@ -3063,7 +3083,7 @@ describe('input', function() {
3063
3083
} ) ;
3064
3084
3065
3085
it ( 'should validate' , function ( ) {
3066
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" /> ') ;
3086
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="10"') ;
3067
3087
3068
3088
helper . changeInputValueTo ( '20' ) ;
3069
3089
expect ( inputElm ) . toBeValid ( ) ;
@@ -3079,7 +3099,7 @@ describe('input', function() {
3079
3099
it ( 'should set the model to the max val if it is greater than the max val' , function ( ) {
3080
3100
scope . value = 110 ;
3081
3101
// Default max is 100
3082
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" /> ') ;
3102
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="{{max}}"') ;
3083
3103
3084
3104
expect ( inputElm ) . toBeValid ( ) ;
3085
3105
expect ( inputElm . val ( ) ) . toBe ( '100' ) ;
@@ -3094,7 +3114,7 @@ describe('input', function() {
3094
3114
3095
3115
it ( 'should adjust the element and model value if the max value changes on-the-fly' , function ( ) {
3096
3116
scope . max = 10 ;
3097
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" /> ') ;
3117
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="{{max}}"') ;
3098
3118
3099
3119
helper . changeInputValueTo ( '5' ) ;
3100
3120
expect ( inputElm ) . toBeValid ( ) ;
@@ -3126,7 +3146,7 @@ describe('input', function() {
3126
3146
3127
3147
} else {
3128
3148
it ( 'should validate if "range" is not implemented' , function ( ) {
3129
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" /> ') ;
3149
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="10"') ;
3130
3150
3131
3151
helper . changeInputValueTo ( '20' ) ;
3132
3152
expect ( inputElm ) . toBeInvalid ( ) ;
@@ -3141,7 +3161,7 @@ describe('input', function() {
3141
3161
3142
3162
it ( 'should not assume a max val of 100 if the max attribute interpolates to a non-number' , function ( ) {
3143
3163
scope . value = 120 ;
3144
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" /> ') ;
3164
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="{{max}}"') ;
3145
3165
3146
3166
expect ( inputElm ) . toBeValid ( ) ;
3147
3167
expect ( inputElm . val ( ) ) . toBe ( '120' ) ;
@@ -3169,7 +3189,7 @@ describe('input', function() {
3169
3189
3170
3190
it ( 'should validate even if the max value changes on-the-fly' , function ( ) {
3171
3191
scope . max = 10 ;
3172
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" /> ') ;
3192
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="{{max}}"') ;
3173
3193
3174
3194
helper . changeInputValueTo ( '5' ) ;
3175
3195
expect ( inputElm ) . toBeValid ( ) ;
@@ -3209,15 +3229,15 @@ describe('input', function() {
3209
3229
it ( 'should set the correct initial value when min and max are specified' , function ( ) {
3210
3230
scope . max = 80 ;
3211
3231
scope . min = 40 ;
3212
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" /> ') ;
3232
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="{{max}}" min="{{min}}"') ;
3213
3233
3214
3234
expect ( inputElm . val ( ) ) . toBe ( '60' ) ;
3215
3235
expect ( scope . value ) . toBe ( 60 ) ;
3216
3236
} ) ;
3217
3237
3218
3238
it ( 'should set element and model value to min if max is less than min' , function ( ) {
3219
3239
scope . min = 40 ;
3220
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" /> ') ;
3240
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" max="{{max}}" min="{{min}}"') ;
3221
3241
3222
3242
expect ( inputElm . val ( ) ) . toBe ( '70' ) ;
3223
3243
expect ( scope . value ) . toBe ( 70 ) ;
@@ -3240,7 +3260,7 @@ describe('input', function() {
3240
3260
// However, currently only Firefox fully inplements the spec when setting the value after the step value changes.
3241
3261
// Other browsers fail in various edge cases, which is why they are not tested here.
3242
3262
it ( 'should round the input value to the nearest step on user input' , function ( ) {
3243
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" step="5" /> ') ;
3263
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" step="5"') ;
3244
3264
3245
3265
helper . changeInputValueTo ( '5' ) ;
3246
3266
expect ( inputElm ) . toBeValid ( ) ;
@@ -3269,7 +3289,7 @@ describe('input', function() {
3269
3289
} ) ;
3270
3290
3271
3291
it ( 'should round the input value to the nearest step when setting the model' , function ( ) {
3272
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" step="5" /> ') ;
3292
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" step="5"') ;
3273
3293
3274
3294
scope . $apply ( 'value = 10' ) ;
3275
3295
expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
@@ -3306,7 +3326,7 @@ describe('input', function() {
3306
3326
it ( 'should validate if "range" is not implemented' , function ( ) {
3307
3327
scope . step = 10 ;
3308
3328
scope . value = 20 ;
3309
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" step="{{step}}" /> ') ;
3329
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" step="{{step}}"') ;
3310
3330
3311
3331
expect ( inputElm . val ( ) ) . toBe ( '20' ) ;
3312
3332
expect ( inputElm ) . toBeValid ( ) ;
@@ -3334,7 +3354,7 @@ describe('input', function() {
3334
3354
3335
3355
it ( 'should validate even if the step value changes on-the-fly' , function ( ) {
3336
3356
scope . step = 10 ;
3337
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" step="{{step}}" /> ') ;
3357
+ var inputElm = compileRangeInput ( ' ng-model="value" name="alias" step="{{step}}"') ;
3338
3358
3339
3359
helper . changeInputValueTo ( '10' ) ;
3340
3360
expect ( inputElm ) . toBeValid ( ) ;
@@ -3377,6 +3397,11 @@ describe('input', function() {
3377
3397
} ) ;
3378
3398
}
3379
3399
} ) ;
3400
+
3401
+ // Helpers
3402
+ function compileRangeInput ( attrs , opts ) {
3403
+ return helper . compileInput ( '<input type="range" ng-input-range ' + attrs + ' />' , opts ) ;
3404
+ }
3380
3405
} ) ;
3381
3406
3382
3407
describe ( 'email' , function ( ) {
0 commit comments