Support choice field

This commit is contained in:
Oliver 2021-06-23 23:36:38 +10:00
parent 1a43198cb7
commit 6162129e3d

View File

@ -193,6 +193,7 @@ function constructCreateForm(url, fields, options={}) {
$(modal).modal('show'); $(modal).modal('show');
attachToggle(modal); attachToggle(modal);
attachSelect(modal);
} }
@ -318,7 +319,7 @@ function constructInput(name, parameters, options={}) {
func = constructNumberInput; func = constructNumberInput;
break; break;
case 'choice': case 'choice':
// TODO: choice field func = constructChoiceInput;
break; break;
case 'field': case 'field':
// TODO: foreign key field! // TODO: foreign key field!
@ -440,6 +441,30 @@ function constructNumberInput(name, parameters, options={}) {
} }
// Construct a "choice" input
function constructChoiceInput(name, parameters, options={}) {
var html = `<select id='id_${name}' class='select form-control' name='${name}'>`;
var choices = parameters.choices || [];
// TODO: Select the selected value!
for (var idx = 0; idx < choices.length; idx++) {
var choice = choices[idx];
html += `<option value='${choice.value}'>`;
html += `${choice.display_name}`;
html += `</option>`;
}
html += `</select>`;
return html;
}
/* /*
* Construct a 'help text' div based on the field parameters * Construct a 'help text' div based on the field parameters
* *