Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements Date input type #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions easyjsonform-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ var ejfBootstrapStyle = {
classList: [],
style: {},
},
FieldDate: {
classList: ['my-3'],
style: {},
},
FieldDateLabel: {
classList: ['form-label'],
style: {},
},
FieldDateInput: {
classList: ['form-control'],
style: {},
},
FieldFile: {
classList: ['my-3'],
style: {},
Expand Down
33 changes: 32 additions & 1 deletion easyjsonform.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,36 @@ class EasyJsonFormFieldTextgroup extends EasyJsonFormField {
}
}

class EasyJsonFormFieldDate extends EasyJsonFormField {
constructor(json = null) {
super(json);
this.type = 'date';
}

formFieldCreate(ejf, position, withValidation = false) {
let validationError = (withValidation && this.validate().length > 0);
let lblFormField = ejf.element('label', 'FieldDateLabel', validationError ? 'ValidationErrorLabel' : null);
lblFormField.htmlFor = `${ejf.id}[${position}]`;
lblFormField.innerHTML = `${this.label}${this.helpText()}`;
let iptFormField = ejf.element('input', 'FieldDateInput', validationError ? 'ValidationErrorInput' : null);
iptFormField.disabled = ejf.options.disabled || false;
iptFormField.id = `${ejf.id}[${position}]`;
iptFormField.name = `${ejf.id}[${position}]`;
iptFormField.type = 'date';
iptFormField.value = this.value;
iptFormField.onchange = () => {this.value = iptFormField.value; if (ejf.options.onValueChange) ejf.options.onValueChange();};
let formField = ejf.element('div', 'FieldDate');
formField.appendChild(lblFormField);
formField.appendChild(iptFormField);
if (validationError) formField.appendChild(this.validationErrorMessage(ejf));
return formField;
}

validate() {
return (this.mandatory && this.value === null) ? ['validation.error.mandatory'] : [];
}
}

class EasyJsonForm {

/**
Expand Down Expand Up @@ -924,7 +954,6 @@ class EasyJsonForm {
});
if (this.builder) this.builderUpdate();
if (this.form) this.formUpdate();
this.onStructureChange();
}

valueExport(mode = 'raw') {
Expand Down Expand Up @@ -990,6 +1019,7 @@ class EasyJsonForm {
'singlechoice': EasyJsonFormFieldSingleChoice,
'multiplechoice': EasyJsonFormFieldMultipleChoice,
'file': EasyJsonFormFieldFile,
'date': EasyJsonFormFieldDate
};
static supportedFileTypes = {
'application/pdf' : {extensions:['pdf']},
Expand Down Expand Up @@ -1043,6 +1073,7 @@ class EasyJsonForm {
"item.properties.mandatory": "Mandatory",
"item.number": "Number",
"item.text": "Text",
"item.date": "Date",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to move this up a line to keep all of the item.text entries together.

"item.text.character.count": "{{chars}} characters",
"item.text.properties.length.max": "Maximum length",
"item.text.properties.length.measure": "Restrict length",
Expand Down