We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Field settings JS changing name of disabled fields

Developer Preview

Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

There is a line of javascript in the field settings area that is renaming disabled fields and it is preventing me from having conditionally disabled fields based on a user’s input.

Is there some way that this script could be limited to First party fields?

// This all kind of came about from needing to preserve radio button
// state for radio buttons but identical names across various groups.
// In an effort not to need to prefix those input names, we'll handle
// it automatically with this function.
function e(t,e,o){t.find(":input").each(function(){var t=a(this),r=t.attr("name"),c=r.replace("el_disabled_"+e+"_","");
       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

It would be nice to keep it for all fields so that everyone can benefit from not having to worry about naming collisions.

Can you help me understand your problem a bit better? When your fieldtype is selected, it should have renamed the inputs back to their original name.

       
Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

It was not changing the field name back for me when I would change to my field’s settings.

What I am doing is showing a field to the user thats disabled and is a ‘url_title’ version of a phrase they are inputting in another field. I do not want them to be able to edit the field but i want the field input to submit.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Ah ok. Is it only the disabled field that isn’t getting its name reset? I’m not seeing this behavior with other fields. Also, we enable all fields on the form once that form is active, are you re-disabling it with JavaScript once it appears? Or how are you disabling it?

Also, if you leave it disabled, it’s not going to be included in POST data, is it?

       
Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

It’s disabled in the html template and that portion of the template itself is hidden until the user makes a choice to use it.

There is a select field and a button next to it to let the user input their own, new item instead of using the select field.

The button hides the select field and reveals 2 input fields, one for the user to input a new name, and another to show a live url_title version of it, just as a convenience for the user.

All of the html is within field’s setting divs and nothing coming in from outside of it except the JS loaded via add_package_js().

I just realized i missed a vital part of what to tell you here about what i was experiencing:

I have it disabled in the html, when i choose my field, then click the button that reveals it, the html disabled url_title-ish field shows up as enabled rather than disabled as it is in html, but it still has the el_disabled name on it so i couldn’t target it to even fix it with JS.

To fix, I had to leave it enabled, then disable it as soon as I show it via JS. That kept it from having the el_disabled rename.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Ah ok. Strange, I’m still not sure why it wouldn’t rename itself back. But yes you would at least need that bit if JS to re-enable the field. So, is that fix alright, then? I know no fix is better, but we really like being able to only send the inputs we need and prevent naming collisions by disabling fields not in use.

       
Greg Ferrell's avatar
Greg Ferrell
102 posts
10 years ago
Greg Ferrell's avatar Greg Ferrell

I’ve got it working and it’s something i am comfortable putting into production but I will say that it’s boggling that it’s not removing itself when the field is selected.

Could you by chance send me the uncompressed JS file where this is located? I might be doing something colliding.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Sure, here it is:

EE.cp.form_group_toggle = function(element) {

 var config = $(element).data('groupToggle'),
  value  = $(element).val();

 // First, disable all inputs
 $.each(config, function (key, data) {
  toggleInputs($('*[data-group="'+data+'"]'), key, false);
 });

 // Then show the selected group and enable its inputs
 $.each(config, function (key, data) {
  var group = $('*[data-group="'+data+'"]');
  group.toggle(key == value);

  if (key == value) {
   toggleInputs(group, key, true);
  }
 });

 // This all kind of came about from needing to preserve radio button
 // state for radio buttons but identical names across various groups.
 // In an effort not to need to prefix those input names, we'll handle
 // it automatically with this function.
 function toggleInputs(container, group_name, enable) {
  container.find(':input').each(function() {

   var input = $(this),
    name = input.attr('name'),
    clean_name = name.replace('el_disabled_'+group_name+'_', '');

   // Disable inputs that aren't shown, we don't need those in POST
   input.attr('disabled', ! enable);

   // Prefixing the name ensures radio buttons will keep their state
   // when changing the visible group, as well as any JS handlers
   // based on name should take note of and inputs that are no
   // longer in their scope
   if (enable) {
    input.attr('name', clean_name);
   } else {
    input.attr('name', 'el_disabled_'+group_name+'_'+clean_name);
   }
  });
 }
}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.