Undisable certain elements inside disabled fieldset
Asked Answered
D

2

9

Is there a way (like an attribute on an element) to 'undisable' a specific element when the parent fieldset is disabled? Preferable without any JavaScript. If not, what is a good practice to disable an entire form with specific exceptions?

<fieldset disabled>
  Name: <input type="text"><br>

  <!-- Email shouldn't be disabled -->
  Email: <input type="text"><br>

  <!-- more fields ... -->
</fieldset>
Demetricedemetris answered 4/2, 2016 at 9:25 Comment(1)
I think it's not possible. <fieldset disabled> is used to disable all field, unless condition given to it. For ex, if you want to remove disable of name text box, then don't give disable in fieldset and using <script> add rest of the text box as disable. Just a suggestion.Pear
C
1

Put your input inside the <legend> element:

<fieldset disabled>
  <legend>
    <label>Email: <input></label>
  </legend>

  <label>Name: <input></label>
  <!-- more fields ... -->
</fieldset>
Carnassial answered 14/3, 2019 at 23:29 Comment(0)
T
0

Dear use this example to achieve your goal.

 $(document).ready(function () {
            $('#form :input').prop('disabled', true);
            $("#btn1").prop('disabled', false);
        })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<fieldset id="form">

  <legend>Personalia:</legend>
  Name: <input type="text" /><br />
  Email: <input type="text" /><br />
  Date of birth: <input type="text" />

  <input id="btn1" type="button" value="See More (Enable this!!) " onclick="ButtonClicked1()" />
  Somethingelse: <input type="text" />
 <input type="button" value="View Details " onclick="ButtonClicked2()"/> 

  </fieldset>
Tervalent answered 7/9, 2016 at 7:8 Comment(3)
Thank you for your answer but I would like to do it without JavaScript.Demetricedemetris
This is a legitimate answer! Though the OP was looking for good practice, he didn't specify that it need not be javascript. How much this hack is good practice is measure in degree not in absolute.Piccard
Here is an answer for <button> elements: https://mcmap.net/q/403017/-how-to-enable-one-button-inside-a-disabled-fieldsetTwombly

© 2022 - 2024 — McMap. All rights reserved.