Fix #19627 - Reset UNSIGNED attribute when changing to non-numeric co… (#20280)

* Fix #19627 - Reset UNSIGNED attribute when changing to non-numeric column type
* Fix eslint array-element-newline violations
* Trigger CI re-run
* Update resources/js/modules/functions.ts

---------

Signed-off-by: Nicolai Ehrhardt <245527909+predictor2718@users.noreply.github.com>
Co-authored-by: Maurício Meneghini Fauth <mauricio@mfauth.com.br>
This commit is contained in:
Nicolai 2026-04-21 20:58:17 +02:00 committed by GitHub
parent ea951ef2a8
commit e3a1824fe4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 0 deletions

View File

@ -731,6 +731,32 @@ export function checkTableEditForm (theForm, fieldsCnt) {
}
}
// Check for UNSIGNED/ZEROFILL on non-numeric types
const $typeField = $('#field_' + i + '_2');
const $attrField = $typeField.closest('tr').find('select[name^="field_attribute"]');
const typeVal = String($typeField.val() || '').toUpperCase();
const attrVal = String($attrField.val() || '').toUpperCase();
if (attrVal === 'UNSIGNED' || attrVal === 'UNSIGNED ZEROFILL' || attrVal === 'ZEROFILL') {
const numTypes = [
'TINYINT',
'SMALLINT',
'MEDIUMINT',
'INT',
'BIGINT',
'FLOAT',
'DOUBLE',
'DECIMAL',
];
elm3 = $('#field_' + i + '_1');
if (numTypes.indexOf(typeVal) === -1 && elm3.val() !== '') {
$attrField.trigger('select');
ajaxShowMessage(typeVal + ' ' + window.Messages.strInvalidAttribute, null, 'error');
$attrField.trigger('focus');
return false;
}
}
if (atLeastOneField === 0) {
id = 'field_' + i + '_1';
if (! emptyCheckTheField(theForm, id)) {
@ -1570,6 +1596,37 @@ function showNoticeForEnum (selectElement) {
/**
* Hides/shows a warning message when LENGTH is used with inappropriate integer type
*/
/**
* Reset the attribute dropdown when the column type is changed
* to a non-numeric type. Attributes like UNSIGNED and ZEROFILL
* are only valid for numeric types.
*/
function resetAttributeForNonNumericType ($typeSelector) {
const type = String($typeSelector.val() || '').toUpperCase();
const numericTypes = [
'TINYINT',
'SMALLINT',
'MEDIUMINT',
'INT',
'BIGINT',
'FLOAT',
'DOUBLE',
'DECIMAL',
];
if (numericTypes.indexOf(type) === -1) {
// Find the attribute select in the same row
const $row = $typeSelector.closest('tr');
const $attrSelect = $row.find('select[name^="field_attribute"]');
const currentAttr = String($attrSelect.val() || '').toUpperCase();
if (currentAttr === 'UNSIGNED' || currentAttr === 'UNSIGNED ZEROFILL'
|| currentAttr === 'ZEROFILL'
) {
$attrSelect.val('');
}
}
}
function showWarningForIntTypes () {
if (! $('div#length_not_allowed').length) {
return;
@ -2144,6 +2201,7 @@ export function onloadEnumSetEditorMessage (): void {
$(document).on('change', 'select.column_type', function () {
showNoticeForEnum($(this));
showWarningForIntTypes();
resetAttributeForNonNumericType($(this));
});
$(document).on('change', 'select.default_type', function () {

View File

@ -116,6 +116,7 @@ final readonly class JavaScriptMessagesController implements InvocableController
'strRadioUnchecked' => __('Select at least one of the options!'),
'strEnterValidNumber' => __('Please enter a valid number!'),
'strEnterValidLength' => __('Please enter a valid length!'),
'strInvalidAttribute' => __('does not support the UNSIGNED attribute.'),
'strAddIndex' => __('Add index'),
'strEditIndex' => __('Edit index'),
/* l10n: Rename a table Index */