mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Improved shopping list item form validation (closes #1226)
This commit is contained in:
parent
d9e42331f9
commit
9f1692e31f
@ -2074,3 +2074,6 @@ msgstr ""
|
|||||||
|
|
||||||
msgid "Print options"
|
msgid "Print options"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "A product or a note is required"
|
||||||
|
msgstr ""
|
||||||
|
@ -167,6 +167,9 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#note").trigger("input");
|
||||||
|
$("#product_id").trigger("input");
|
||||||
});
|
});
|
||||||
|
|
||||||
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
|
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
|
||||||
@ -235,4 +238,16 @@ if (GetUriParam("embedded") !== undefined)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var eitherRequiredFields = $("#product_id,#product_id_text_input,#note");
|
||||||
|
eitherRequiredFields.on("input", function()
|
||||||
|
{
|
||||||
|
eitherRequiredFields.attr("required", "");
|
||||||
|
if (!$(this).val().isEmpty())
|
||||||
|
{
|
||||||
|
eitherRequiredFields.not(this).removeAttr("required");
|
||||||
|
}
|
||||||
|
|
||||||
|
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
|
||||||
|
});
|
||||||
|
|
||||||
Grocy.Components.UserfieldsForm.Load();
|
Grocy.Components.UserfieldsForm.Load();
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
@php if(!isset($disabled)) { $disabled = false; } @endphp
|
@php if(!isset($disabled)) { $disabled = false; } @endphp
|
||||||
@php if(empty($hint)) { $hint = ''; } @endphp
|
@php if(empty($hint)) { $hint = ''; } @endphp
|
||||||
@php if(empty($nextInputSelector)) { $nextInputSelector = ''; } @endphp
|
@php if(empty($nextInputSelector)) { $nextInputSelector = ''; } @endphp
|
||||||
|
@php if(empty($validationMessage)) { $validationMessage = 'You have to select a product'; } @endphp
|
||||||
|
|
||||||
<div class="form-group"
|
<div class="form-group"
|
||||||
data-next-input-selector="{{ $nextInputSelector }}"
|
data-next-input-selector="{{ $nextInputSelector }}"
|
||||||
@ -57,7 +58,7 @@
|
|||||||
value="{{ $product->id }}">{{ $product->name }}</option>
|
value="{{ $product->id }}">{{ $product->name }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
<div class="invalid-feedback">{{ $__t('You have to select a product') }}</div>
|
<div class="invalid-feedback">{{ $__t($validationMessage) }}</div>
|
||||||
<div id="custom-productpicker-error"
|
<div id="custom-productpicker-error"
|
||||||
class="form-text text-danger d-none"></div>
|
class="form-text text-danger d-none"></div>
|
||||||
<div id="flow-info-InplaceAddBarcodeToExistingProduct"
|
<div id="flow-info-InplaceAddBarcodeToExistingProduct"
|
||||||
|
@ -62,8 +62,9 @@
|
|||||||
@include('components.productpicker', array(
|
@include('components.productpicker', array(
|
||||||
'products' => $products,
|
'products' => $products,
|
||||||
'nextInputSelector' => '#amount',
|
'nextInputSelector' => '#amount',
|
||||||
'isRequired' => false,
|
'isRequired' => true,
|
||||||
'prefillById' => $productId
|
'prefillById' => $productId,
|
||||||
|
'validationMessage' => 'A product or a note is required'
|
||||||
))
|
))
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -79,9 +80,11 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="note">{{ $__t('Note') }}</label>
|
<label for="note">{{ $__t('Note') }}</label>
|
||||||
<textarea class="form-control"
|
<textarea class="form-control"
|
||||||
|
required
|
||||||
rows="10"
|
rows="10"
|
||||||
id="note"
|
id="note"
|
||||||
name="note">@if($mode == 'edit'){{ $listItem->note }}@endif</textarea>
|
name="note">@if($mode == 'edit'){{ $listItem->note }}@endif</textarea>
|
||||||
|
<div class="invalid-feedback">{{ $__t('A product or a note is required') }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@include('components.userfieldsform', array(
|
@include('components.userfieldsform', array(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user