Jump to content

Javascript in fields of rendered form


airjohn

Recommended Posts

Hello forum

I have a module that uses the below code to render the register form.

          {assign value=$register_form.formFields var="formFields"} 
          {foreach from=$formFields item="field"}
            {form_field field=$field} 
          {/foreach}

I need to insert a small javascript on some fields that does upper case during typing. Is there any way to edit the fields of the form before it is rendered?

Thanks

 

Link to comment
Share on other sites

Hi EvaF

Thanks for your response.

The problem with css is that fields are not saved in capital on the database. 

The same question derives on the address-form.tpl, if someone wants to do uppercase and save fields in capital, what would be the solution?

Link to comment
Share on other sites

aha, I didn't realized it

so do it using javascript with specific fields

<script type="text/javascript">
    $(document).ready(function ($){
      $(".register-form input[name='lastname'], .register-form input[name='firstname']").keyup(function(){
  		$(this).val( $(this).val().toUpperCase() );
	  });
    });
</script>  

 

Edited by EvaF (see edit history)
Link to comment
Share on other sites

Thanks EvaF! Yes it looks that it works.

This is what I finally used.

$(document).ready(function(){
    $("input.form-control[name='firstname'], input.form-control[name='lastname']").keyup(function(){
        $(this).val($(this).val().toUpperCase());
    });
});

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...