EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on March 11, 2015, 01:03:14 AM



Title: Changing Form Element name attribute [Solved]
Post by: devnull on March 11, 2015, 01:03:14 AM
As a work around for the other post I have opened regarding cascading forms I am trying a different approach.

How can I change the name attribute of all elem,ents in a form ?

I have tried this which works on textboxes, numbrerspinners, dateboxes but does not work on comboboxes
[script]
  $('form#seqf input[name]').each(function(){
    $(this).attr('name','SEQ_'+$(this).attr('name'));
  })

[/script]


Title: Re: Changin Form Element name attribute
Post by: Opan Mustopah on March 11, 2015, 01:27:36 AM
did you already try to getting textbox element first?

Code:
var tx = $('#cb').combobox('textbox');
tx.attr('name', 'new_name');

hope it helps


Title: Re: Changin Form Element name attribute
Post by: devnull on March 11, 2015, 01:35:11 AM
Hi;

Thanks for helping, but I do not have IDs set for every input, and my forms have a lot of elements in them.

I would need to assign both an ID and a name to every element in every form and that is just not practical in this case.



Title: Re: Changin Form Element name attribute
Post by: devnull on March 11, 2015, 02:31:11 AM
Or how can I rename the fields programmatically BEFORE easyui processes them ?

I tried your suggestion, but that won't rename it either:

Code:
  var tx = $('#XXX').combobox('textbox');
  tx.attr('name', 'new_name');


Title: Re: Changin Form Element name attribute
Post by: aswzen on March 11, 2015, 03:09:10 AM
do you know if easyui combobox its only a coverup of the original select option?
the original select option with original ID hidden under the combobox.

http://www.jeasyui.com/forum/index.php?topic=4560.0 (http://www.jeasyui.com/forum/index.php?topic=4560.0)


Title: Re: Changin Form Element name attribute
Post by: Opan Mustopah on March 11, 2015, 08:41:14 AM
can you post some of your code here?


Title: Re: Changin Form Element name attribute
Post by: devnull on March 11, 2015, 04:16:12 PM
Quote
can you post some of your code here?

This is the code I have it works for all inputs except for combobox:

Code:
  $('form#seqf input[name]').each(function(){
    $(this).attr('name','SEQ_'+$(this).attr('name'));
  })


Title: Re: Changin Form Element name attribute
Post by: stworthy on March 11, 2015, 07:25:18 PM
Please extend a new form method to achieve this functionality.
Code:
$.extend($.fn.form.methods, {
changeFieldName: function(jq, fn){
return jq.each(function(){
var f = $(this); // the form object
$.map(['name','textboxName','sliderName'], function(name){
f.find('['+name+']').each(function(){
$(this).attr(name, fn($(this).attr(name)));
})
})
});
}
});

The code below add a prefix for each names.
Code:
$('#seqf').form('changeFieldName', function(name){
  return 'SEQ_' + name;
});

To restore their original names, call this:
Code:
$('#seqf').form('changeFieldName', function(name){
  return name.substr(4)
});


Title: Re: Changin Form Element name attribute
Post by: devnull on March 11, 2015, 07:52:57 PM
Brilliant  :)

Exactly what I was looking for, your support really is outstanding.

Thank you.