Create a Jump menu with Niceforms

Category

Blog Development
24 December, 2014 0

We’ve been trying out niceforms.js, a javascript api for web forms customization created by Thomas Watson. Thanks to him, forms look much nicer now. ?

You can download it and see an intro on how to use it here: http://www.emblematiq.com/lab/niceforms/

We used it to transform a jump menu that looked like this:

into this:

It is quite easy to use, but my problem started when I wanted to use <select> as a jump menu. The way to do this is to create the select tag and then use the onchange event to navigate to the selected page. Your original select would look something like this:

<select onchange=”submit()”><option selected=”selected” value=”page1″>Go to page1</option><option value=”page2″>Go topage2</option></select>

This works perfectly fine without using niceforms, but the select tag doesn’t look nice at all (the look & feel is browser dependent). To make it look nicer, we used niceforms, but…

Since niceforms hides the original select tag and creates <div>’s to render a nicer select, the select’s onchange event never gets called. Thomas wrote something about this problem, but since we had to dig a bit deeper into the implementation to see how to access the original selection, we are putting our solution here.

In order to call the original onchange event of the select tag, you need to edit the original niceforms.js and replace the line 538:

el.lnk._onclick = el.onclick || function () {};

with this (call the original onchange event when the selected div gets clicked):

el.lnk._onclick = el.onclick || function () {  if (this.ref.oldClassName.indexOf(“NFOnChange”) > -1){    this.ref.options[this.pos].selected = “selected”;    //Call the original onchange event    this.ref.onchange();  }};

After doing this, you need to add the NFOnChange class to your select tag, like this:

<select class=”NFOnChange” onchange=”submit()”>

That’s it! After these 2 easy steps you’ll have a nice jump menu!

bkadmin
Wednesday December 24, 2014 - 22:12 Blog, Development
Recent posts
Reclaim your disk space from Xcode

Do you have problems with the space on your disk? You are in the right place! This post is for […]

Read More…

Continue reading
25 June, 2020
RoR – Get your exceptions notified via Slack

Have you ever wanted to be one step ahead, and be notified of any unwanted exception before your users have […]

Read More…

Continue reading
18 October, 2018
Easy creation of a new Node + React project

Starting a new project is something everybody loves to do. However, some steps are always the same for every project. […]

Read More…

Continue reading
3 October, 2018
Learning SCRUM with LEGOS

In Kreitech, we know about Scrum, and we apply it in many of our projects, which gives us very positive […]

Read More…

Continue reading
19 September, 2018