Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

radio.js 09 Jul 2013 06:43 #7924

  • VeCrea
  • VeCrea's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
The radio.js in /administrator/your_coook_component/dom/assets/bootstrap/js/radio.js doesn't do its job as i would like him to do.
It works fine if there's only two choices (boolean, shows green button when you click on Yes, red button when you click on No)
But if you have more choices, like an enumeration field that is configured to display as Radio, then it all falls appart : the last button becomes green when clicked (because it's related to the 1 of the boolean i guess), but other buttons receive btn-undefined as class.
Here is my version of radio.js : i loose red/green in boolean (choice i make is always green), but it works with everything i throw at him.
(function($){
	var colors = {'':'primary','0':'danger','1':'success'};
	$('document').ready(function(){
		$(".btn-group label").click(function() {			
			var label = $(this);
			var input = $('#' + label.attr('for'));
			if (!input.prop('checked')) {
				label.closest('.btn-group').find("label").removeClass('active'
					+	' btn-' + colors['']
					+	' btn-' + colors['0'] 
					+	' btn-' + colors['1']);
				
				//label.addClass('active btn-' + colors[input.val()]);
				label.addClass('active btn-success');
				input.prop('checked', true);
			}
		});
		$(".btn-group input[checked=checked]").each(function() {
			//$("label[for=" + $(this).attr('id') + "]").addClass('active btn-' + colors[$(this).val()]);
			$("label[for=" + $(this).attr('id') + "]").addClass('active btn-success');
		});
	});
})(jQuery);

Please Log in or Create an account to join the conversation.

radio.js 29 Jul 2013 10:50 #10617

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Fixed.
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.072 seconds

  Joomla Developpers won't be able to live without J-Cook's Component Creator! Check it out - it'll save you a heap of time coding so you can concentrate on the creative part of developing!
Mind-Your-Biz-Online

Get Started