BaseHtmlAttr.js
2 years ago
FileExtensionHtmlAttr.js
2 years ago
MaxFileSizeHtmlAttr.js
2 years ago
MaxFilesHtmlAttr.js
2 years ago
RemainingCalcAttr.js
2 years ago
RemainingCalcAttr.js
39 lines
| 1 | import BaseHtmlAttr from './BaseHtmlAttr'; |
| 2 | |
| 3 | function RemainingCalcAttr() { |
| 4 | BaseHtmlAttr.call( this ); |
| 5 | |
| 6 | this.attrName = 'remaining'; |
| 7 | |
| 8 | this.isSupported = function ( input ) { |
| 9 | return input.attrs.hasOwnProperty( 'maxLength' ); |
| 10 | }; |
| 11 | |
| 12 | this.setInput = function ( input ) { |
| 13 | BaseHtmlAttr.prototype.setInput.call( this, input ); |
| 14 | const { maxLength } = input.attrs; |
| 15 | const current = input.value.current?.length ?? 0; |
| 16 | |
| 17 | this.initial = maxLength.value.current - current; |
| 18 | }; |
| 19 | |
| 20 | this.addWatcherAttr = () => {}; |
| 21 | |
| 22 | this.observe = function () { |
| 23 | BaseHtmlAttr.prototype.observe.call( this ); |
| 24 | |
| 25 | this.input.value.watch( () => this.updateAttr() ); |
| 26 | this.input.attrs.maxLength.value.watch( () => this.updateAttr() ); |
| 27 | }; |
| 28 | |
| 29 | this.updateAttr = function () { |
| 30 | const { maxLength } = this.input.attrs; |
| 31 | const current = this.input.value.current?.length ?? 0; |
| 32 | |
| 33 | this.value.current = maxLength.value.current - current; |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | RemainingCalcAttr.prototype = Object.create( BaseHtmlAttr.prototype ); |
| 38 | |
| 39 | export default RemainingCalcAttr; |