diff --git a/public/js/helpers.js b/public/js/helpers.js index 6f51905..8d8399c 100644 --- a/public/js/helpers.js +++ b/public/js/helpers.js @@ -41,6 +41,16 @@ var dom_els = (element) => { return domEls(element); } +/** + * Check to see if val is empty + * @param {string} val - The string to test emptiness for + * @return {boolean} True if string is empty + */ +var isEmpty = (val) => { + let regex = /^\s*$/; + return regex.test(val); +} + /** * Validate a form and highlight each field that fails validation. * @param {string} element - The class name or ID of the element containing the fields to validate. @@ -54,7 +64,9 @@ var validateForm = (form) => { try { domEls(`${form} .required`).forEach((el) => { changeCss(el, '!border-red-500', 'remove', true); - if (el.value === '') { + console.log('value:', el.value); + console.log(isEmpty(el.value)); + if (isEmpty(el.value)) { let el_name = el.getAttribute('name'); let el_parent = el.getAttribute('data-parent'); let error_message = el.getAttribute('data-error-message'); diff --git a/public/js/select.js b/public/js/select.js index e61d2b2..19f4e75 100644 --- a/public/js/select.js +++ b/public/js/select.js @@ -5,6 +5,7 @@ class BladewindSelect { searchInput; selectItems; isMultiple; + required; displayArea; formInput; maxSelection; @@ -24,10 +25,11 @@ class BladewindSelect { this.searchInput = `${this.itemsContainer} .bw_search`; this.selectItems = `${this.itemsContainer} .bw-select-items .bw-select-item`; this.isMultiple = (dom_el(this.rootElement).getAttribute('data-multiple') === 'true'); + this.required = (dom_el(this.rootElement).getAttribute('data-required') === 'true'); this.formInput = `input.bw-${this.name}`; dom_el(this.displayArea).style.maxWidth = `${(dom_el(this.rootElement).offsetWidth - 40)}px`; this.maxSelection = -1; - this.canClear = false; + this.canClear = (!this.required && !this.isMultiple); this.enabled = true; } diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index 8b909ad..2c9dd65 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -153,17 +153,22 @@ $suffix_is_icon = true; $suffix_icon_css = 'hidden cursor-pointer dark:!bg-dark-900/60 dark:hover:!bg-dark-900 !p-0.5 !rounded-full bg-gray-400 !stroke-2 hover:bg-gray-600 text-white'; } + if($attributes->has('readonly', 'disabled')){ + if($attributes->get('readonly') == 'false') $attributes = $attributes->except('readonly'); + if($attributes->get('disabled') == 'false') $attributes = $attributes->except('disabled'); + } @endphp