()
| 77 | } |
| 78 | |
| 79 | build () { |
| 80 | if (!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle(), this.isRequired()) |
| 81 | if (this.schema.description) this.description = this.theme.getFormInputDescription(this.translateProperty(this.schema.description)) |
| 82 | if (this.options.infoText) this.infoButton = this.theme.getInfoButton(this.translateProperty(this.options.infoText)) |
| 83 | |
| 84 | this.format = this.schema.format |
| 85 | if (!this.format && this.schema.media && this.schema.media.type) { |
| 86 | this.format = this.schema.media.type.replace(/(^(application|text)\/(x-)?(script\.)?)|(-source$)/g, '') |
| 87 | } |
| 88 | if (!this.format && this.options.default_format) { |
| 89 | this.format = this.options.default_format |
| 90 | } |
| 91 | if (this.options.format) { |
| 92 | this.format = this.options.format |
| 93 | } |
| 94 | |
| 95 | /* Specific format */ |
| 96 | if (this.format) { |
| 97 | /* Text Area */ |
| 98 | if (this.format === 'textarea') { |
| 99 | this.input_type = 'textarea' |
| 100 | this.input = this.theme.getTextareaInput() |
| 101 | /* Range Input */ |
| 102 | } else if (this.format === 'range') { |
| 103 | this.input_type = 'range' |
| 104 | let min = this.schema.minimum || 0 |
| 105 | let max = this.schema.maximum || Math.max(100, min + 1) |
| 106 | let step = 1 |
| 107 | if (this.schema.multipleOf) { |
| 108 | if (min % this.schema.multipleOf) min = Math.ceil(min / this.schema.multipleOf) * this.schema.multipleOf |
| 109 | if (max % this.schema.multipleOf) max = Math.floor(max / this.schema.multipleOf) * this.schema.multipleOf |
| 110 | step = this.schema.multipleOf |
| 111 | } |
| 112 | |
| 113 | this.input = this.theme.getRangeInput(min, max, step, this.description, this.formname) |
| 114 | this.input.setAttribute('id', this.formname) |
| 115 | /* HTML5 Input type */ |
| 116 | } else { |
| 117 | this.input_type = 'text' |
| 118 | if (['button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', 'number', 'password', 'radio', 'reset', 'search', 'submit', 'tel', 'text', 'time', 'url', 'week'].includes(this.format)) { |
| 119 | this.input_type = this.format |
| 120 | } |
| 121 | this.input = this.theme.getFormInputField(this.input_type) |
| 122 | } |
| 123 | /* Normal text input */ |
| 124 | } else { |
| 125 | this.input_type = 'text' |
| 126 | this.input = this.theme.getFormInputField(this.input_type) |
| 127 | } |
| 128 | |
| 129 | /* minLength, maxLength, and pattern */ |
| 130 | if (typeof this.schema.maxLength !== 'undefined') this.input.setAttribute('maxlength', this.schema.maxLength) |
| 131 | if (typeof this.schema.pattern !== 'undefined') this.input.setAttribute('pattern', this.schema.pattern) |
| 132 | else if (typeof this.schema.minLength !== 'undefined') this.input.setAttribute('pattern', `.{${this.schema.minLength},}`) |
| 133 | |
| 134 | if (this.options.compact) { |
| 135 | this.container.classList.add('compact') |
| 136 | } else if (this.options.input_width) this.input.style.width = this.options.input_width |
nothing calls this directly
no test coverage detected