Update number input on blur
This commit is contained in:
		
							parent
							
								
									93dee41c11
								
							
						
					
					
						commit
						b0fbdfb6e9
					
				| 
						 | 
					@ -264,6 +264,7 @@ function configDialog(style) {
 | 
				
			||||||
            va,
 | 
					            va,
 | 
				
			||||||
            type: va.type,
 | 
					            type: va.type,
 | 
				
			||||||
            onfocus: va.type === 'number' ? selectAllOnFocus : null,
 | 
					            onfocus: va.type === 'number' ? selectAllOnFocus : null,
 | 
				
			||||||
 | 
					            onblur: va.type === 'number' ? updateVarOnBlur : null,
 | 
				
			||||||
            onchange: updateVarOnChange,
 | 
					            onchange: updateVarOnChange,
 | 
				
			||||||
            oninput: updateVarOnInput
 | 
					            oninput: updateVarOnInput
 | 
				
			||||||
          };
 | 
					          };
 | 
				
			||||||
| 
						 | 
					@ -311,15 +312,23 @@ function configDialog(style) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  function updateVarOnBlur(e = {}) {
 | 
				
			||||||
 | 
					    const value = Number(this.value);
 | 
				
			||||||
 | 
					    const clamped = clampValue(value, this.va);
 | 
				
			||||||
 | 
					    if (clamped === value) {
 | 
				
			||||||
 | 
					      this.va.value = value;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (e.type === 'blur') {
 | 
				
			||||||
 | 
					      this.value = clamped;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function updateVarOnChange() {
 | 
					  function updateVarOnChange() {
 | 
				
			||||||
    if (this.type === 'range') {
 | 
					    if (this.type === 'range') {
 | 
				
			||||||
      this.va.value = Number(this.value);
 | 
					      this.va.value = Number(this.value);
 | 
				
			||||||
      updateRangeCurrentValue(this.va, this.va.value);
 | 
					      updateRangeCurrentValue(this.va, this.va.value);
 | 
				
			||||||
    } else if (this.type === 'number') {
 | 
					    } else if (this.type === 'number') {
 | 
				
			||||||
      const value = Number(this.value);
 | 
					      updateVarOnBlur.call(this);
 | 
				
			||||||
      if (clampValue(value, this.va) === value) {
 | 
					 | 
				
			||||||
        this.va.value = value;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      this.va.value = this.type !== 'checkbox' ? this.value : this.checked ? '1' : '0';
 | 
					      this.va.value = this.type !== 'checkbox' ? this.value : this.checked ? '1' : '0';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user