Disabling specific radio options
See original GitHub issueI’m submitting a feature request.
I ran into some behavior I didn’t expect in radios fields. It seems logical that setting disabled: true
on a single option would result in disabled="disabled"
on that particular option. However, options are only disabled when the whole radios field is disabled. I looked at fieldRadios.vue and to me it seems like the most simple solution would be to change this:
<template lang="pug">
.radio-list(:disabled="disabled", v-attributes="'wrapper'")
label(v-for="item in items", :class="{'is-checked': isItemChecked(item)}", v-attributes="'label'")
input(:id="getFieldID(schema)", type="radio", :disabled="disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)", :class="schema.fieldClasses", :required="schema.required", v-attributes="'input'")
| {{ getItemName(item) }}
into this:
<template lang="pug">
.radio-list(:disabled="disabled", v-attributes="'wrapper'")
label(v-for="item in items", :class="{'is-checked': isItemChecked(item), 'is-disabled': disabled || item.disabled}", v-attributes="'label'")
input(:id="getFieldID(schema)", type="radio", :disabled="disabled || item.disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)", :class="schema.fieldClasses", :required="schema.required", v-attributes="'input'")
| {{ getItemName(item) }}
This makes sure that a radio option is disabled whenever its parent is disabled entirely and whenever that particular option is disabled itself.
Example (expected behavior after option label): https://jsfiddle.net/Anoesj/qd8fv430/
Version: 2.3.2
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
HTML DOM Input Radio disabled Property - W3Schools
The disabled property sets or returns whether a radio button should be disabled, or not. A disabled element is unusable and un-clickable.
Read more >How to disable radio button using JavaScript - javatpoint
You can enable and disable the radio button by using the disabled property of HTML DOM. Set this property to true (disable=true) to...
Read more >Angular Formly - Disable individual Radio Options
Generally there are two ways for that: Using [attr.disabled]; Using fieldset tag. Using [attr.disabled]. <input type="radio" name="enabled" ...
Read more >Add the posibility to disable some radio options in a ... - Drupal
You can disable options via custom code/module using hook_preprocess_radios() and/or the radios element #process callback. Log in or register to ...
Read more >Disable one radio button option only
Hello all,. I've got a radio button with let's say {"Apple", "Orange", "Strawberry"} as options. I want users to only be able to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@zoul0813 One minor improvement would be adding a class “is-disabled” to labels belonging to disabled radio inputs. This allows for easy radio styling. For example, right now, we can’t put opacity: 0.4 on the label text when the radio input is disabled.
I’ll see if I can make some time to work on this, little bit busy though. I would still go for “is-disabled” since “is-checked” is already being used.