Skip to content
Merged
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
2 changes: 1 addition & 1 deletion public/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/wc.js

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions views/mdc/assets/js/components/selects.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,38 @@ export class VSelect extends dirtyableMixin(visibilityObserverMixin(VBaseCompone
this.select.vComponent = this;
this.recalcWhenVisible(this);
this.originalValue = this.value();
this.helperDisplay = this.root.getElementById(`${element.id}-input-helper-text`);
this.origHelperText = this.helperDisplay.innerHTML.trim();
}

prepareSubmit(params) {
params.push([this.name(), this.value()]);
}

// Called whenever a form is about to be submitted.
// returns true on success
// returns on failure return an error object that can be processed by VErrors:
// { email: ["email must be filled", "email must be from your domain"] }
// { :page: ["must be filled"] }
validate(formData) {
console.debug('Select validate', formData);
const isValid = this.select.checkValidity();
if (isValid) {
this.resetHelperDisplay();

return true;
}

const message = this.helperDisplay.dataset.validationError ?
this.helperDisplay.dataset.validationError :
this.select.validationMessage;

const errorMessage = {};
errorMessage[this.element.id] = [message];
this.element.classList.add('mdc-select-field--invalid');
return errorMessage;
}

name() {
return this.select.name;
}
Expand Down Expand Up @@ -61,4 +87,20 @@ export class VSelect extends dirtyableMixin(visibilityObserverMixin(VBaseCompone
isDirty() {
return this.dirtyable && this.value() !== this.originalValue;
}

resetHelperDisplay() {
if (this.shouldShowHelperText) {
this.helperDisplay.innerHTML = this.origHelperText;
this.helperDisplay.classList.remove('v-hidden', 'mdc-text-field-helper-text--validation-msg');
}
else {
this.helperDisplay.classList.add('v-hidden');
}

this.element.classList.remove('mdc-select-field--invalid');
}

get shouldShowHelperText() {
return this.helperDisplay && Boolean(this.origHelperText);
}
}
4 changes: 4 additions & 0 deletions views/mdc/assets/scss/components/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ select {

.mdc-select__label--float-above {
white-space: nowrap;
}

.mdc-select-field--invalid {
border-color: #b00020;
}
1 change: 1 addition & 0 deletions views/mdc/components/_select.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<% if comp.required %>required<% end %>
<% if comp.disabled %>disabled<% end %>
class="mdc-select__native-control"
aria-controls="<%= comp.id %>-input-helper-text"
<%= partial("components/event", locals: {comp: comp,
events: comp.events,
parent_id: "#{comp.id}-input"}) if comp.events&.any? %>
Expand Down
Loading