MCPcopy Create free account
hub / github.com/chhoumann/quickadd / renderField

Method renderField

src/preflight/OnePageInputModal.ts:155–580  ·  view source on GitHub ↗
(req: FieldRequirement)

Source from the content-addressed store, hash-verified

153 }
154
155 private renderField(req: FieldRequirement) {
156 const setValue = (id: string, value: string) => {
157 this.result.set(id, value);
158 this.updatePreviewDebounced();
159 };
160 const starting = this.initialValues.get(req.id) ?? req.defaultValue ?? "";
161
162 switch (req.type) {
163 case "textarea": {
164 const setting = new Setting(this.contentEl).setName(
165 this.decorateLabel(req),
166 );
167 if (req.description) setting.setDesc(req.description);
168 const input = new TextAreaComponent(setting.controlEl);
169 input
170 .setPlaceholder(req.placeholder ?? "")
171 .setValue(starting)
172 .onChange((v) => setValue(req.id, v));
173 input.inputEl.addClass("qa-onepage-textarea");
174 break;
175 }
176 case "text": {
177 const setting = new Setting(this.contentEl).setName(
178 this.decorateLabel(req),
179 );
180 if (req.description) setting.setDesc(req.description);
181 const input = new TextComponent(setting.controlEl);
182 input
183 .setPlaceholder(req.placeholder ?? "")
184 .setValue(starting)
185 .onChange((v) => setValue(req.id, v));
186 break;
187 }
188 case "number": {
189 // |type:number — a numeric input so the one-page form rejects
190 // non-numeric text like the runtime NumberInputPrompt does.
191 const setting = new Setting(this.contentEl).setName(
192 this.decorateLabel(req),
193 );
194 if (req.description) setting.setDesc(req.description);
195 const input = new TextComponent(setting.controlEl);
196 input.inputEl.type = "number";
197 input.inputEl.inputMode = "decimal";
198 if (req.numericConfig?.min !== undefined) {
199 input.inputEl.min = String(req.numericConfig.min);
200 }
201 if (req.numericConfig?.max !== undefined) {
202 input.inputEl.max = String(req.numericConfig.max);
203 }
204 input.inputEl.step =
205 req.numericConfig?.step !== undefined
206 ? String(req.numericConfig.step)
207 : "any";
208 const normalizedStarting = req.numericConfig
209 ? normalizeNumericValue(starting, req.numericConfig)
210 : starting;
211 input
212 .setPlaceholder(req.placeholder ?? "")

Callers 1

displayMethod · 0.95

Calls 15

decorateLabelMethod · 0.95
onChangeMethod · 0.95
setPlaceholderMethod · 0.95
setValueMethod · 0.95
addOptionMethod · 0.95
setValueMethod · 0.95
onChangeMethod · 0.95
setDisabledMethod · 0.95
normalizeNumericValueFunction · 0.90
normalizeSliderValueFunction · 0.90
formatISODateFunction · 0.90

Tested by

no test coverage detected