add autonumeric format & fix editor btn in tarifa impresion maquina

This commit is contained in:
amazuecos
2025-02-09 13:12:37 +01:00
parent 3efec5e6cb
commit 9b7c6c4ec1

View File

@ -389,13 +389,17 @@
}, { }, {
name: "precio", name: "precio",
attr: { attr: {
type: "number" type: "text",
} name : "precio",
class :"autonumeric"
}
}, { }, {
name: "margen", name: "margen",
attr: { attr: {
type: "number" type: "text",
} name : "margen",
class :"autonumeric"
}
}, { }, {
"name": "maquina_id", "name": "maquina_id",
"type": "hidden" "type": "hidden"
@ -409,8 +413,37 @@
] ]
} ); } );
editor.on('open', (event) => {
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
autoNumericInstance.remove()
}
new AutoNumeric(this, {
decimalCharacter: ",",
digitGroupSeparator: ".",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
});
})
})
editor.on( 'preSubmit', function ( e, d, type ) { editor.on( 'preSubmit', function ( e, d, type ) {
if (d.data) {
Object.keys(d.data).forEach(function (key) {
// Find all elements with class .autonumeric
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
// Get raw value and update the corresponding field
let rawValue = autoNumericInstance.getNumericString();
d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used
}
});
});
}
if ( type === 'create'){ if ( type === 'create'){
d.data[0]['maquina_id'] = id; d.data[0]['maquina_id'] = id;
} }
@ -511,9 +544,9 @@
return '<?= lang('MaquinasTarifasImpresions.colorhq') ?>'; return '<?= lang('MaquinasTarifasImpresions.colorhq') ?>';
} }
}, },
{ 'data': 'precio' }, { 'data': 'precio',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'margen' }, { 'data': 'margen',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'is_deleted',}, { 'data': 'is_deleted'},
{ {
data: actionBtns, data: actionBtns,
className: 'row-edit dt-center' className: 'row-edit dt-center'
@ -523,7 +556,7 @@
columnDefs: [ columnDefs: [
{ {
target: 4, target: 4,
visible: false visible: true
}, },
{ {
orderable: false, orderable: false,
@ -585,7 +618,7 @@
}, },
{ 'data': 'papel_generico'}, { 'data': 'papel_generico'},
{ 'data': 'papel_impresion'}, { 'data': 'papel_impresion'},
{ 'data': 'gramaje'}, { 'data': 'gramaje',render : (d) => `<span class="autonumeric">${d}</span>`},
{ 'data': 'bn'}, { 'data': 'bn'},
{ 'data': 'color'}, { 'data': 'color'},
{ 'data': 'cubierta'}, { 'data': 'cubierta'},
@ -731,9 +764,19 @@
fields: [ { fields: [ {
name: "formas" name: "formas"
}, { }, {
name: "internas" name: "internas",
attr: {
type: "text",
name : "internas",
class :"autonumeric"
}
}, { }, {
name: "externas" name: "externas",
attr: {
type: "text",
name : "externas",
class :"autonumeric"
}
}, { }, {
"name": "maquina_id", "name": "maquina_id",
"type": "hidden" "type": "hidden"
@ -746,7 +789,37 @@
}, },
] ]
} ); } );
editor3.on('open', (event) => {
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
autoNumericInstance.remove()
}
new AutoNumeric(this, {
decimalCharacter: ",",
digitGroupSeparator: ".",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
});
})
})
editor3.on('preSubmit', (e, d, type) => {
if (d.data) {
Object.keys(d.data).forEach(function (key) {
// Find all elements with class .autonumeric
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
// Get raw value and update the corresponding field
let rawValue = autoNumericInstance.getNumericString();
d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used
}
});
});
}
})
editor3.on( 'preSubmit', function ( e, d, type ) { editor3.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){ if ( type === 'create'){
@ -799,8 +872,8 @@
}), }),
columns : [ columns : [
{ 'data': 'formas' }, { 'data': 'formas' },
{ 'data': 'internas' }, { 'data': 'internas',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'externas' }, { 'data': 'externas',render : (d) => `<span class="autonumeric">${d}</span>` },
{ data: actionBtns, { data: actionBtns,
className: 'row-edit dt-center'} className: 'row-edit dt-center'}
], ],