Showing posts with label Twitter Bootstrap. Show all posts
Showing posts with label Twitter Bootstrap. Show all posts

Wednesday, April 24, 2013

Twitter Bootstrap JS: Using ButtonGroup (radio type) selected button in a form

This is the function that we use to watch which buttons have been activated in a Twitter Bootstrap `buttonGroup` of a radio type.  You need to have a hidden form field so the function can put the values from the selected buttons in there for your form post.

Using it is as simple as adding this to your document ready of your page.  The first argument of the function call is the id of the `buttonGroup` and the second argument is the id of the hidden input where the function will store the values of the activated buttons:
    $(document).ready(function() {
        watchButtonsRadio('#utilitiesLocatedBtnGroup', '#utilities_located');
});

Add this function to the general or utility JS file that is loaded on every page:
function watchButtonsRadio(buttonGroup, hiddenInput) {
    $('button', $(buttonGroup)).each(function() {

        var originalValue = $(hiddenInput).val();

        //Convert booleans to numeric
        if (originalValue == 'true') {
            originalValue = 1;
        } else if (originalValue == 'false') {
            originalValue = 0;
        }

        if ($(this).val() == originalValue) {
            $(this).trigger('click');
        }

        $(this).live('click', function() {
            // Hidden by default doesn't trigger the change event so manually fire it
            $(hiddenInput).val($(this).val()).change();
            console.log(hiddenInput + ': ' + $(hiddenInput).val());
        });
    });
}

Monday, October 15, 2012

Grails48 Hackathon - Nov. 9-12 - Join the Minneapolis Team

I want to invite you to join the Minneapolis Team for the Grails48 Hackathon that is occurring November 9-12.  It's easy to join at hackathon.io:

http://grails48.hackathon.io/teams/view/615

You don't have to be there the whole time -- even part of a day would be helpful.

Our project is EnlistApp. Enlist is an open source and free application that aims to help non-profits organize volunteers, track volunteer hours and management volunteer rewards.  This application will directly benefit Team Ortho -- they put on running races in the Twin Cities. They support research, education, and advancements in orthopaedic technology; and to promote good muscular, skeletal, and joint health by encouraging an active lifestyle including training for and participating in amateur athletic events.

We already have a start on it here -- uses Grails, Twitter Bootstrap, JQuery, etc in case you want to check it out:

https://github.com/maestrofjp/Enlist-Grails

I'm working on a location.  Doug Sabers has offered ReachLocal's offices (below where we have the GUM meetings) and I'm waiting to hear back from him to confirm.

In the meantime, come join the team for the hackathon.