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.075 seconds
Great UX great performance and definitely a time saver. It only took me 10 minutes of playing around before purchasing a subscription and right now I just want to throw more money at you! I just started a new project and after just 4h I can already tell it probably saved me several days of work. I'm building a wholesale ordering system with sales rep management. I have not looked at the code yet but so far: impressive.
flip (Forum)

Get Started