vendor/assets/javascripts/webshims/shims/combos/33.js in webshims-rails-1.12.7 vs vendor/assets/javascripts/webshims/shims/combos/33.js in webshims-rails-1.13.0

- old
+ new

@@ -196,37 +196,48 @@ $.each({stepUp: 1, stepDown: -1}, function(name, stepFactor){ var stepDescriptor = webshims.defineNodeNameProperty('input', name, { prop: { value: function(factor){ - var step, val, dateVal, valModStep, alignValue, cache, base, attrVal; + var step, val, valModStep, alignValue, cache, base, attrVal; var type = getType(this); if(typeModels[type] && typeModels[type].asNumber){ cache = {type: type}; if(!factor){ factor = 1; webshims.warn("you should always use a factor for stepUp/stepDown"); } factor *= stepFactor; - val = $.prop(this, 'valueAsNumber'); + - if(isNaN(val)){ - webshims.info("valueAsNumber is NaN can't apply stepUp/stepDown "); - throw('invalid state error'); - } + step = webshims.getStep(this, type); if(step == 'any'){ webshims.info("step is 'any' can't apply stepUp/stepDown"); throw('invalid state error'); } webshims.addMinMaxNumberToCache('min', $(this), cache); webshims.addMinMaxNumberToCache('max', $(this), cache); - + + val = $.prop(this, 'valueAsNumber'); + + if(factor > 0 && !isNaN(cache.minAsNumber) && (isNaN(val) || cache.minAsNumber > val)){ + $.prop(this, 'valueAsNumber', cache.minAsNumber); + return; + } else if(factor < 0 && !isNaN(cache.maxAsNumber) && (isNaN(val) || cache.maxAsNumber < val)){ + $.prop(this, 'valueAsNumber', cache.maxAsNumber); + return; + } + + if(isNaN(val)){ + val = 0; + } + base = cache.minAsNumber; if(isNaN(base) && (attrVal = $.prop(this, 'defaultValue'))){ base = typeModels[type].asNumber( attrVal ); } @@ -247,11 +258,11 @@ val = alignValue.toFixed(5) * 1; } if( (!isNaN(cache.maxAsNumber) && val > cache.maxAsNumber) || (!isNaN(cache.minAsNumber) && val < cache.minAsNumber) ){ webshims.info("max/min overflow can't apply stepUp/stepDown"); - throw('invalid state error'); + return; } $.prop(this, 'valueAsNumber', val); } else if(stepDescriptor.prop && stepDescriptor.prop._supvalue){ @@ -601,10 +612,11 @@ writeable: false } }); } -});;webshims.register('form-datalist', function($, webshims, window, document, undefined, options){ +}); +;webshims.register('form-datalist', function($, webshims, window, document, undefined, options){ "use strict"; var lazyLoad = function(name){ if(!name || typeof name != 'string'){ name = 'DOM'; }