From be386e1ce8885a8be2606aecd11c7ff46b44ee2f Mon Sep 17 00:00:00 2001 From: "Michael K. Ocansey" Date: Wed, 7 Aug 2024 18:54:37 +0000 Subject: [PATCH 1/3] Fix: #308 ensure line feeds, tabs, empty strings, carriage returns don't pass validation for emptiness --- public/js/helpers.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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'); From 1858ecef10d8cab8c13332328a6a516844910f39 Mon Sep 17 00:00:00 2001 From: "Michael K. Ocansey" Date: Sun, 11 Aug 2024 15:53:02 +0000 Subject: [PATCH 2/3] Fix: #310 --- resources/views/components/input.blade.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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
merge(['class' => "bw-input peer $is_required $name $placeholder_color $size"]) }} - type="{{ $type }}" - id="{{ $name }}" - name="{{ $name }}" - value="{{ html_entity_decode($selected_value) }}" - autocomplete="new-password" - placeholder="{{ $placeholder_label }}{{$required_symbol}}" + {{ $attributes->class(["bw-input peer $is_required $name $placeholder_color $size"])->merge([ + 'type' => $type, + 'id' => $name, + 'name' => $name, + 'value' => html_entity_decode($selected_value), + 'autocomplete' => "new-password", + 'placeholder' => $placeholder_label.$required_symbol, + ]) }} @if($error_message != '') data-error-message="{{$error_message}}" data-error-inline="{{$show_error_inline}}" From cfdf99fa609795df6432c4c16a2ce4e2f6b2558f Mon Sep 17 00:00:00 2001 From: "Michael K. Ocansey" Date: Sun, 11 Aug 2024 19:07:32 +0000 Subject: [PATCH 3/3] Fix: #309 --- public/js/select.js | 4 +++- resources/views/components/select.blade.php | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) 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/select.blade.php b/resources/views/components/select.blade.php index 79bb58c..6786ad2 100644 --- a/resources/views/components/select.blade.php +++ b/resources/views/components/select.blade.php @@ -164,7 +164,8 @@ }
\ No newline at end of file