1
I have a table that when you double-click on one of its fields it becomes an input and this input, when I press enter, becomes a table field again, but sometimes it doesn’t work right away, I have to click the input and then press enter. I wish I could click on the cell of the table, it turn an input, I change the information, give enter and already was.
My code JS:
function updateFabricante(op) {
let fabricante = $(`#fabricante${op}`).text() || $(`#fabricante`).val()
$(`#fabricante${op}`).dblclick(function(){
$(this).html(`<input type="text" required name="fabricante" id="fabricante" value="${fabricante}">`);
$(`#fabricante`).focus();
});
$(`#fabricante`).on('keypress',function(e) {
if(e.which === 13) {
let fabricante = $(`#fabricante`).val();
$(`#fabricante${op}`).html(fabricante);
return false;
}
});
}
(Explanation to expedite)
Where
op: Specifies which cell I am selecting, are varied, from 0 to n
manufacturer${op}: ID of the field I selected
manufacturer: input ID
Just in advance, it is incorrect to place the event handlers within the function (at least in this case). That’s because if you call more than once the function with the same
op
, will multiply the manipulators, may cause unexpected behavior, which seems to be the case.– Sam
How are you calling the function
updateFabricante
to activate the double click?– Sam
Yes, I noticed I was wrong now.
– eduardo vitorino