Jquery Mobile Form - Select Menus Part II

    In part II of this tutorial on creating select menus using Jquery Mobile, we will discuss some customization techniques like overriding the default native OS select menu or disabling an option or creating a multi-select select box. It is advisable that you take a look at part I of this tutorial where we have discussed the basics of the select menu. In case you have decided to proceed with this part, then we are ready to take a look at the code that follows.



    In the example code above, you will observe 2 different selects. We will be discussing the following data attributes and HTML5 properties that will enhance the select menus further.

1. data-native-menu="false"
2. data-placeholder="true"
3. disabled
4. multiple

    As seen in the first implementation, by adding the data attribute data-native-menu="false" we can simply override the native OS menu control and display a pop-up containing the options in a listview. If there are a large number of options, the framework will automatically create a new "page" populated with a standard listview for the options.

    To create a placeholder for the select we just need to include a data attribute data-placeholder="true" to an option which holds the placeholder text. This option will then be styled accordingly and will not be selectable. In case you want to disable an option just add disable to that option and that option will be styled as a disabled listview. All the above three things are part of the first implementation in the above example.

    Lets now take a look at how to create a multi select select box. It is as simple as it sounds a big task. Just add keyword multiple to your select element (as seen in the second implementation) and the framework will style each of your option as a listview with a checkbox and you can select multiple options. Each of the options selected will be populated as comma seperated list on the custom select button. To top this off Jquery Mobile framework will aslo add a count bubble on the select button indicating how many options are selected.

    Hope you have enjoyed this post and the other form elements tutorials. Drop a line in case this has helped you, or if you have any concerns, comments on the post or the series of examples that I have shared so far. You can also check out the comprehensive list of examples on Jquery Mobile listview. Till next time, keep sharing - Sharing is Caring.

Popular posts from this blog

Where does Google get it's live traffic data from?

jQuery Mobile's Next Big Step

Geodesic Polyline