@@ -731,6 +731,32 @@ export function checkTableEditForm (theForm, fieldsCnt) {
731731 }
732732 }
733733
734+ // Check for UNSIGNED/ZEROFILL on non-numeric types
735+ const $typeField = $ ( '#field_' + i + '_2' ) ;
736+ const $attrField = $typeField . closest ( 'tr' ) . find ( 'select[name^="field_attribute"]' ) ;
737+ const typeVal = String ( $typeField . val ( ) || '' ) . toUpperCase ( ) ;
738+ const attrVal = String ( $attrField . val ( ) || '' ) . toUpperCase ( ) ;
739+ if ( attrVal === 'UNSIGNED' || attrVal === 'UNSIGNED ZEROFILL' || attrVal === 'ZEROFILL' ) {
740+ const numTypes = [
741+ 'TINYINT' ,
742+ 'SMALLINT' ,
743+ 'MEDIUMINT' ,
744+ 'INT' ,
745+ 'BIGINT' ,
746+ 'FLOAT' ,
747+ 'DOUBLE' ,
748+ 'DECIMAL' ,
749+ ] ;
750+ elm3 = $ ( '#field_' + i + '_1' ) ;
751+ if ( numTypes . indexOf ( typeVal ) === - 1 && elm3 . val ( ) !== '' ) {
752+ $attrField . trigger ( 'select' ) ;
753+ ajaxShowMessage ( typeVal + ' ' + window . Messages . strInvalidAttribute , null , 'error' ) ;
754+ $attrField . trigger ( 'focus' ) ;
755+
756+ return false ;
757+ }
758+ }
759+
734760 if ( atLeastOneField === 0 ) {
735761 id = 'field_' + i + '_1' ;
736762 if ( ! emptyCheckTheField ( theForm , id ) ) {
@@ -1570,6 +1596,37 @@ function showNoticeForEnum (selectElement) {
15701596/**
15711597 * Hides/shows a warning message when LENGTH is used with inappropriate integer type
15721598 */
1599+ /**
1600+ * Reset the attribute dropdown when the column type is changed
1601+ * to a non-numeric type. Attributes like UNSIGNED and ZEROFILL
1602+ * are only valid for numeric types.
1603+ */
1604+ function resetAttributeForNonNumericType ( $typeSelector ) {
1605+ const type = String ( $typeSelector . val ( ) || '' ) . toUpperCase ( ) ;
1606+ const numericTypes = [
1607+ 'TINYINT' ,
1608+ 'SMALLINT' ,
1609+ 'MEDIUMINT' ,
1610+ 'INT' ,
1611+ 'BIGINT' ,
1612+ 'FLOAT' ,
1613+ 'DOUBLE' ,
1614+ 'DECIMAL' ,
1615+ ] ;
1616+
1617+ if ( numericTypes . indexOf ( type ) === - 1 ) {
1618+ // Find the attribute select in the same row
1619+ const $row = $typeSelector . closest ( 'tr' ) ;
1620+ const $attrSelect = $row . find ( 'select[name^="field_attribute"]' ) ;
1621+ const currentAttr = String ( $attrSelect . val ( ) || '' ) . toUpperCase ( ) ;
1622+ if ( currentAttr === 'UNSIGNED' || currentAttr === 'UNSIGNED ZEROFILL'
1623+ || currentAttr === 'ZEROFILL'
1624+ ) {
1625+ $attrSelect . val ( '' ) ;
1626+ }
1627+ }
1628+ }
1629+
15731630function showWarningForIntTypes ( ) {
15741631 if ( ! $ ( 'div#length_not_allowed' ) . length ) {
15751632 return ;
@@ -2144,6 +2201,7 @@ export function onloadEnumSetEditorMessage (): void {
21442201 $ ( document ) . on ( 'change' , 'select.column_type' , function ( ) {
21452202 showNoticeForEnum ( $ ( this ) ) ;
21462203 showWarningForIntTypes ( ) ;
2204+ resetAttributeForNonNumericType ( $ ( this ) ) ;
21472205 } ) ;
21482206
21492207 $ ( document ) . on ( 'change' , 'select.default_type' , function ( ) {
0 commit comments