From 15c055c02c4d9da00de65cb970d4c64ba95b510f Mon Sep 17 00:00:00 2001 From: DrManac Date: Mon, 26 Apr 2021 14:37:15 +0300 Subject: [PATCH] required attribure in Select & RadioButtons --- packages/lib/src/radio.ts | 5 ++++- packages/lib/src/select.ts | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/lib/src/radio.ts b/packages/lib/src/radio.ts index 9fd75f7..421d208 100644 --- a/packages/lib/src/radio.ts +++ b/packages/lib/src/radio.ts @@ -52,6 +52,7 @@ export const RadioButtons: FactoryComponent = () => { description, options, isMandatory, + required, checkboxClass, onchange: callback, }, @@ -77,6 +78,7 @@ export const RadioButtons: FactoryComponent = () => { onchange, groupId, disabled, + required, className: checkboxClass, checked: r.id === checkedId, }) @@ -96,7 +98,7 @@ export interface IRadioButton extends Attributes { } export const RadioButton: FactoryComponent = () => ({ - view: ({ attrs: { id, groupId, label, onchange, className = 'col s12', checked, disabled } }) => { + view: ({ attrs: { id, groupId, label, onchange, className = 'col s12', checked, disabled, required } }) => { return m( `div`, { className }, @@ -107,6 +109,7 @@ export const RadioButton: FactoryComponent = () => ({ }`, { onclick: onchange ? () => onchange(id) : undefined, + required } ), m('span', m.trust(label)), diff --git a/packages/lib/src/select.ts b/packages/lib/src/select.ts index 9f97e06..a929861 100644 --- a/packages/lib/src/select.ts +++ b/packages/lib/src/select.ts @@ -78,6 +78,7 @@ export const Select: FactoryComponent = () => { helperText, placeholder, isMandatory, + required, iconName, disabled, classes, @@ -113,11 +114,12 @@ export const Select: FactoryComponent = () => { const clear = newRow ? '.clear' : ''; const isDisabled = disabled ? '[disabled]' : ''; const isMultiple = multiple ? '[multiple]' : ''; + const isRequired = required ? '[required]' : ''; const noValidSelection = options.filter((o) => isSelected(o.id, initialValue)).length === 0; return m(`.input-field.select-space${clear}`, { className, key }, [ iconName && m('i.material-icons.prefix', iconName), m( - `select[id=${id}]${isDisabled}${isMultiple}`, + `select[id=${id}]${isDisabled}${isMultiple}${isRequired}`, { oncreate: ({ dom }) => { state.instance = M.FormSelect.init(dom, { classes, dropdownOptions });