Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double click disabled select box to enable

I'm trying to enable all form elements on double click of the form, and have simplified code as follows:

<form>
    <input type="text" name="foo" disabled />
    <select name="bar" disabled>
        <option>a</option>
        <option>b</option>
    </select>
</form>

<script type="text/javascript">
    $(function() {
        $('form').dblclick(function() {
            $(this).find('input,select').removeAttr('disabled');
        });
    });
</script>

However, the form double click event does not fire while hovering over the disabled <select> element. And unfortunately, the "readonly" attribute does not work on <select> elements.

This is for an internal application, and I only need it function on Google Chrome.

UPDATE:

I'm getting a bunch of answers on this, and I think I need to revise my question to help guide the process... What does the W3C spec on disabled form elements say?... It appears the double click event doesn't fire on disabled <input> elements in Firefox for example. Perhaps the fact that it fires in Chrome is a bug/misalignment w/ spec that I can't count on always being there.

At the moment, watching for the double click event on an absolutely positioned wrapper element above the form seems like the best option... even though I hate adding extra wrapper elements.

like image 882
David Budiac Avatar asked Jun 26 '13 15:06

David Budiac


2 Answers

I would suggest putting a div overlaying the entire form, and place the click handler on that. Disabled fields do not fire click handlers.

like image 66
James Montagne Avatar answered Sep 21 '22 22:09

James Montagne


You could use that:

DEMO

$(function () {    
    $('form').dblclick(function () {
        $(this).find('input,select').removeProp('disabled').removeClass('no-pointer');
    }).find(':input').addClass('no-pointer');
});

CSS:

.no-pointer{pointer-events:none}
like image 21
A. Wolff Avatar answered Sep 21 '22 22:09

A. Wolff