EasyUI Forum
September 14, 2025, 12:52:50 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Changing Form Element name attribute [Solved]  (Read 16402 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« 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]
« Last Edit: March 11, 2015, 07:53:17 PM by devnull » Logged

-- Licensed User --
Opan Mustopah
Full Member
***
Posts: 164


Indonesia


View Profile Email
« Reply #1 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
Logged

-- Bajak Otak --
*** Sorry for my bad english :3 ***
--JeasyUI version 1.4--
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #2 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.

Logged

-- Licensed User --
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #3 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');
« Last Edit: March 11, 2015, 02:38:22 AM by devnull » Logged

-- Licensed User --
aswzen
Sr. Member
****
Posts: 287


Indonesian

aswzen
View Profile WWW Email
« Reply #4 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
Logged

Regards,
Sigit

- Indonesian jEasyUI Facebook page : https://www.facebook.com/groups/jeasyuiid/
Opan Mustopah
Full Member
***
Posts: 164


Indonesia


View Profile Email
« Reply #5 on: March 11, 2015, 08:41:14 AM »

can you post some of your code here?
Logged

-- Bajak Otak --
*** Sorry for my bad english :3 ***
--JeasyUI version 1.4--
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #6 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'));
  })
Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #7 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)
});
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #8 on: March 11, 2015, 07:52:57 PM »

Brilliant  Smiley

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

Thank you.
Logged

-- Licensed User --
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!