Welcome, Guest
Username: Password: Remember me

TOPIC: Show label depending on bool

Show label depending on bool 08 Feb 2013 14:58 #6688

Hi,

I have a form that have a bool field and a text field.
I would like to show a different label for the text field depending on the bool option chosen.
How can i do this?
thanks in advance
The administrator has disabled public write access.

Re: Show label depending on bool 08 Feb 2013 19:11 #6689

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
jQuery i guess ?
Changing the value of the label should be no problem if you add an id to the label.
Need more help on this ?
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Show label depending on bool 08 Feb 2013 20:15 #6690

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hey @robertocook,

-- UPDATED -- I foolishly missed out the jQuery call on the element - OOPS! - writing this response in a rush earlier :oops: so, I apologise if you are unfamiliar with jQuery and it caused you any headaches!
PLEASE SEE UPDATED code below:


jQuery (or another JS library) is definitely how you would want to do this if it is on a form. Please see here: www.j-cook.pro/forum/35-jquery/4481-show...ds-in-front-end-form

It's a demo on how to show/hide, disable input fields dependent on a radio button. You could easily adapt it to target the ID or CLASS of the dom element you want to manipulate.

Of course, if this is not in a form and/or the change of label that is required need not be interactive and instead, needs to change for each record returned where a certain column (field) == true, then you need to override the JDom output.

Of course, you could equally stick with jQuery for this just like the forms. However, instead, you'd need to target the container of the text want and retrieve as opposed to the input fields' IDs/classes, then, set it's text property using the text() method;
//****** JS *********/
//  init some vars
var myLabel =  jQuery("#myFieldID.className");// change myFieldID & className to your bool field
var boolField.val() = jQuery("input[id='myYesNo']"); // change myYesNo to your bool field

// Check value of bool to set label
if(boolField == 0){ // or false... whatever your setup
  // myLabel.text("Label if bool false"); --- UPDATED -- see next line //
  jQuery(myLabel).text("Label if bool false");
}else{
  // myLabel.text("Label if bool true"); --- UPDATED -- see next line //
  jQuery(myLabel).text("Label if bool true");
}
You could easily wrap this in function, store it in a [your_component].js file to include. Then you can call it anytime you like. Furthermore, adding a couple of parameters - bool and radio for instance - you could make it completely dynamic. Just pass them like switchLabel("#radioID", "input[id='myYesNo']");

Anyway,

hope it helps!

Gez

Anyway,
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
Last Edit: 08 Feb 2013 23:16 by JoomGuy. Reason: Reason: UPDATED -- missed out the jQuery call on the element - OOPS!
The administrator has disabled public write access.

Re: Show label depending on bool 20 Feb 2013 11:17 #6820

hi !!
how i implement it ?
i do not know where and how to put the Onchange() !!
i tried putting an alert('hi); on
<script language="javascript" type="text/javascript">
jQuery(document).ready(function(){
jQuery("#adminForm").validationEngine();

alert('hi');
});

and i did not get it !!

thanks,
Albert
The administrator has disabled public write access.
Time to create page: 0.112 seconds

Get Started