question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disabling specific radio options

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Anoesjcommented, Dec 17, 2018

@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.

0reactions
Anoesjcommented, Dec 17, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found