Skip to main content
Topic: set a field with content from another field? (Read 1067 times) previous topic - next topic

set a field with content from another field?

Hello all,
I'm going deeply with phprad! I really appreciate it.
Now I would like to set a field using the content from another field.
I'm trying to create a websafe product name.
Example:
Field 1 contains: My new product n 1
Field 2 (hidden or read-only) should get Field 1 and transform it to "my-new-product-n-1"

Can I do this with phprad?
Thanks in advance.
tony

Re: set a field with content from another field?

Reply #1
@sweetman‍ You can use the client event configuration in AddPage Field Properties to write you jQuery code to handle that for you, thanks.

 

Re: set a field with content from another field?

Reply #2
Wow! works perfectly!
I used this code in the ClientEvend dialog box to convert a field to a slug (string suitable to be used as URL parameter):
Code: [Select]
$('#ctrl-field1').on('change blur keyup', function(){ 
var alias = $('#ctrl-field1').val();
alias = alias.toLowerCase();
alias = alias.replace(/[àáâãäå]/g, 'a');
       alias = alias.replace(/[èéêë]/g,   'e');
       alias = alias.replace(/[ìíîï]/g,   'i');
       alias = alias.replace(/[òóôõö]/g,  'o');
        alias = alias.replace(/[ùúûü]/g,   'u');
       alias = alias.replace(/[ýÿ]/g,     'y');
       alias = alias.replace(/[^\w ]+/g,'');
       alias = alias.replace(/ +/g,'-');
$('#ctrl-field2').val(alias)

});

HTH
Thanks Willvin
Ciao ;)
Tony