In our new tutorial I would like to show you how to create really modern and stylish settings page. Lets assume that you’ve had an own project. And, you are looking how to create admin panel for your project with some settings. If so – just continue reading and check our demonstration. In order to make this page with options I use jQuery mobile library. I think that this is really great library to create such pages as settings page.
Ok, please download our source files and let’s start coding !
[sociallocker]
[/sociallocker]
Step 1. HTML
In order to use jQuery mobile we should link this library and css file:
2 | <link href="css/main.css" rel="stylesheet" type="text/css" /> |
3 | <link rel="stylesheet" href="jquery.mobile/jquery.mobile-1.1.1.min.css" /> |
6 | <script src="jquery.mobile/jquery.mobile-1.1.1.min.js"></script> |
Now, the HTML markup of our form:
001 | <form action="index.php" method="post" data-ajax="false"> |
002 | <div class="ui-body ui-body-c"> |
003 | <h2>How to create a stylish setting page</h2> |
005 | <div data-role="fieldcontain"> |
006 | <label for="text-p-1">Param 1:</label> |
007 | <input type="text" name="text-p-1" id="text-p-1" value="" data-mini="true" /> |
009 | <div data-role="fieldcontain"> |
010 | <label for="text-p-2">Param 2:</label> |
011 | <input type="text" name="text-p-2" id="text-p-2" value="" data-mini="true" /> |
014 | <div data-role="fieldcontain"> |
015 | <label for="basic_settings">Show basic settings:</label> |
016 | <select name="basic_settings" id="basic_settings" data-role="slider" data-mini="true"> |
017 | <option value="off">Off</option> |
018 | <option value="on">On</option> |
022 | <div class="ui-body ui-body-c hidden_basic_settings" style="display:none"> |
024 | <div data-role="fieldcontain"> |
025 | <label for="text-1">Text Input 1:</label> |
026 | <input type="text" name="text-1" id="text-1" value="" data-mini="true" /> |
028 | <div data-role="fieldcontain"> |
029 | <label for="text-2">Text Input 2:</label> |
030 | <input type="text" name="text-2" id="text-2" value="" data-mini="true" /> |
033 | <div data-role="fieldcontain"> |
034 | <label for="switch">Switch selector:</label> |
035 | <select name="switch" id="switch" data-role="slider" data-mini="true"> |
036 | <option value="off">Off</option> |
037 | <option value="on">On</option> |
041 | <div data-role="fieldcontain"> |
042 | <label for="slider">Slider:</label> |
043 | <input type="range" name="slider" id="slider" value="0" min="0" max="100" data-mini="true" /> |
047 | <div data-role="fieldcontain"> |
048 | <label for="advanced_settings">Show advanced settings:</label> |
049 | <select name="advanced_settings" id="advanced_settings" data-role="slider" data-mini="true"> |
050 | <option value="off">Off</option> |
051 | <option value="on">On</option> |
055 | <div class="ui-body ui-body-c hidden_advanced_settings" style="display:none"> |
057 | <div data-role="fieldcontain"> |
058 | <fieldset data-role="controlgroup" data-type="horizontal" data-mini="true"> |
059 | <legend>Multiple checkboxes:</legend> |
060 | <input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" /> |
061 | <label for="checkbox-1">Checkbox 1</label> |
062 | <input type="checkbox" name="checkbox-2" id="checkbox-2" class="custom" /> |
063 | <label for="checkbox-2">Checkbox 2</label> |
064 | <input type="checkbox" name="checkbox-3" id="checkbox-3" class="custom" /> |
065 | <label for="checkbox-3">Checkbox 3</label> |
069 | <div data-role="fieldcontain"> |
070 | <fieldset data-role="controlgroup" data-mini="true"> |
071 | <legend>Radio buttons:</legend> |
072 | <input type="radio" name="radio-1" id="radio-1" value="1" /> |
073 | <label for="radio-1">Radio 1</label> |
074 | <input type="radio" name="radio-1" id="radio-2" value="2" /> |
075 | <label for="radio-2">Radio 2</label> |
076 | <input type="radio" name="radio-1" id="radio-3" value="3" /> |
077 | <label for="radio-3">Radio 3</label> |
078 | <input type="radio" name="radio-1" id="radio-4" value="4" /> |
079 | <label for="radio-4">Radio 4</label> |
083 | <div data-role="fieldcontain"> |
084 | <label for="select" class="select">Selector:</label> |
085 | <select name="select" id="select" data-native-menu="false" data-mini="true"> |
086 | <option value="value1">Option 1</option> |
087 | <option value="value2">Option 2</option> |
088 | <option value="value3">Option 3</option> |
089 | <option value="value4">Option 4</option> |
090 | <option value="value5">Option 5</option> |
095 | <fieldset class="ui-grid-a"> |
096 | <div class="ui-block-a"><button type="submit" data-theme="b" data-mini="true">Submit</button></div> |
097 | <div class="ui-block-b"><button type="cancel" data-theme="c" data-mini="true">Cancel</button></div> |
You can see there next form elements: text fields, switch selector, slider, multiple checkboxes, radio buttons, selector and buttons. Now – please pay attention that I separated all the fields into 2 sections: hidden_basic_settings and hidden_advanced_settings. The both sections are invisible by default (display:none). I’m going to use switch selectors to show / hide our hidden sections. This is very attractice. You can just click (or drag) these switchers in order to slide our sub-sections. Of course, to have it made I had to handle selector’s events. Look at this JS code:
01 | $(document).ready(function() { |
02 | $('#basic_settings').change(function(event, ui) { |
03 | if ($(this).attr('value') == 'on') { |
04 | $('.hidden_basic_settings').slideDown(500); |
06 | $('.hidden_basic_settings').slideUp(500); |
09 | $('#advanced_settings').change(function(event, ui) { |
10 | if ($(this).attr('value') == 'on') { |
11 | $('.hidden_advanced_settings').slideDown(500); |
13 | $('.hidden_advanced_settings').slideUp(500); |
Everything is easy, isn’t it? When we change status of our selector – we slide our sub-sections with settings.
Conclusion
Today we have reviewed creation of stylish and contemporary forms. If you really like the result – do not be lazy – share it with your friends by clicking on our social buttons in the form below. Good luck in your work!