You are viewing limited content. For full access, please sign in.

Question

Question

Event Attributes on Input Fields

asked on September 7, 2021

Hi guys.

Do you know how to put an event attribute on a Forms input field?

I´m doing like this, but it does not work.

 

0 0

Replies

replied on September 7, 2021

The way I would do it would be...

Give a class name to the field, say CSS Class: MyField

Then in Javascript

$(document).ready( function() {

  $('.MyField input').on("onkeyup", function() {

    $(this).val( number($(this).val()));

  });

});
This is hand typed here and untested so beware of minor syntax errors.

2 0
replied on September 7, 2021

Im doing this but it does not work, yet


$(document).ready( function() {

  $(".limite input").on('onkeyup', function() {

    Numeros($(this).val());

  });
  
  function Numeros(string){//Solo numeros
    var out = '';
    var filtro = '1234567890';//Caracteres validos
    
    //Recorrer el texto y verificar si el caracter se encuentra en la lista de validos 
    for (var i=0; i<string.length; i++)
       if (filtro.indexOf(string.charAt(i)) != -1) 
             //Se añaden a la salida los caracteres validos
         out += string.charAt(i);
    
    //Retornar valor filtrado
    return out;

});
  
 

1 0
replied on September 7, 2021

I can see a few possible issues with the code so far.

Most important is it should be .on('keyup',...  not .on('onkeyup',...

Second, you're returning the "out" variable, but you're not actually using it to update your input field value or anything.

It looks like you are trying to limit the input field to numbers only. If so, why don't you just use a Number type field and let Forms handle that for you?

1 0
replied on September 8, 2021

Thanks!!!

0 0
replied on September 7, 2021

That field is only for adding a custom CSS class to the input element; there is no out-of-the-box way to add event attributes.

If you want to add a custom event handler, you need to do it with code in the JavaScript tab like what James describes in his post.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.