Skip to content

Commit

Permalink
Merge pull request #314 from mkocansey/development
Browse files Browse the repository at this point in the history
release/production
  • Loading branch information
mkocansey authored Aug 11, 2024
2 parents 5d9bc26 + ca97438 commit cc32886
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
14 changes: 13 additions & 1 deletion public/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion public/js/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BladewindSelect {
searchInput;
selectItems;
isMultiple;
required;
displayArea;
formInput;
maxSelection;
Expand All @@ -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;
}

Expand Down
19 changes: 12 additions & 7 deletions resources/views/components/input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

<div class="relative w-full dv-{{$name}} @if($add_clearing) mb-4 @endif">
<input
{{ $attributes->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}}"
Expand Down
5 changes: 3 additions & 2 deletions resources/views/components/select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
}
</style>
<div class="relative bw-select bw-select-{{$input_name}} @if($add_clearing) mb-3 @endif"
data-multiple="{{$multiple}}" data-type="{{ $data !== 'manual' ? 'dynamic' : 'manual'}}"
data-multiple="{{$multiple}}" data-required="{{$required?'true':'false'}}"
data-type="{{ $data !== 'manual' ? 'dynamic' : 'manual'}}"
@if(!empty($filter)) data-filter="{{ $filter}}" @endif
@if($data == 'manual' && $selected_value != '') data-selected-value="{{implode(',',$selected_value)}}" @endif>
<div tabindex="0"
Expand Down Expand Up @@ -237,5 +238,5 @@ class="bw-{{$input_name}} @if($required) required @endif"
bw_{{ $input_name }}.maxSelectable({{$max_selectable}}, '{{ sprintf($max_error_message, $max_selectable) }}');
@endif
@if(!empty($filter)) bw_{{ $input_name }}.filter('{{ $filter }}');
@endif @if(!($required && $multiple == 'false')) bw_{{ $input_name }}.clearable();@endif
@endif @if(!$required && $multiple == 'false') bw_{{ $input_name }}.clearable();@endif
</script>

0 comments on commit cc32886

Please sign in to comment.