Add is_required column to pp_shop_products_custom_fields table

This commit introduces a new column `is_required` to the `pp_shop_products_custom_fields` table. The column is of type TINYINT, cannot be null, and has a default value of 1. This change is intended to enhance the product custom fields by allowing the specification of whether a field is mandatory.
This commit is contained in:
2025-08-19 20:31:44 +02:00
parent 84333c1b59
commit ef15f16e18
16 changed files with 137 additions and 28 deletions

View File

@@ -485,6 +485,8 @@ jQuery( 'body' ).on( 'click', '#g-cancel', function() {
});
});
jQuery( 'body' ).on( 'click', '#g-save, #g-edit-save', function()
{
var back_url = jQuery( this ).attr( 'back_url' );
@@ -534,6 +536,44 @@ jQuery( 'body' ).on( 'click', '#g-save, #g-edit-save', function()
}
});
/* === UNIWERSALNA NORMALIZACJA CHECKBOXÓW TABLICOWYCH ===
Dla wszystkich input[type=checkbox] z name="coś[]":
- jeśli wartości są typu boolean ('', '1', 'on', 'true', 'yes') → zbuduj pełną tablicę 1/0 w kolejności DOM,
tak aby indeksy były ciągłe [0..N-1] nawet gdy część jest odznaczona.
- jeśli to lista wyboru (np. categories[] z różnymi ID) → pozostaw jak z serializeArray (tylko zaznaczone).
*/
(function normalizeCheckboxArrays() {
var $form = jQuery('#fg-' + gtable);
if (!$form.length) return;
// zgrupuj checkboxy po pełnej nazwie (z [] na końcu)
var groups = {};
$form.find('input[type="checkbox"][name$="[]"]').each(function () {
var n = this.name; // np. "required[]", "visible[]", "categories[]"
(groups[n] = groups[n] || []).push(this);
});
Object.keys(groups).forEach(function (nameWithBrackets) {
var inputs = groups[nameWithBrackets];
if (!inputs.length) return;
// sprawdź, czy wszystkie wartości wyglądają „booleanowo”
var uniqVals = Array.from(new Set(inputs.map(function (el) {
return (el.getAttribute('value') || '').toLowerCase();
})));
var boolSet = new Set(['', '1', 'on', 'true', 'yes']);
var isBooleanLike = uniqVals.every(function (v) { return boolSet.has(v); });
if (isBooleanLike) {
var baseKey = nameWithBrackets.replace(/\[\]$/, ''); // usuń [] → "required", "visible"
// pełna tablica 1/0 w kolejności w formularzu
formattedValues[baseKey] = inputs.map(function (el) { return el.checked ? '1' : '0'; });
}
// else: zostawiamy formattedValues tak jak już zbudowane z serializeArray()
});
})();
var url = jQuery( this ).attr( 'url' );
if ( url !== '' )