FEATURE: allow wizard checkbox field to be disabled (#17916)

* FEATURE: allow wizard checkbox field to be disabled

* Changes per review feedback
This commit is contained in:
Arpit Jalan 2022-08-15 05:52:07 +05:30 committed by GitHub
parent 0be67cb513
commit 3a21618e4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 4 deletions

View File

@ -7,6 +7,7 @@ export default Component.extend({
":wizard-container__field",
"typeClasses",
"field.invalid",
"field.disabled",
],
@discourseComputed("field.type", "field.id")

View File

@ -1,5 +1,5 @@
<label class="wizard-container__label">
<Input @type="checkbox" class="wizard-container__checkbox" @checked={{this.field.value}} />
<Input @type="checkbox" disabled={{this.field.disabled}} class="wizard-container__checkbox" @checked={{this.field.value}} />
<span class="wizard-container__checkbox-slider"></span>
{{#if this.field.icon}}
{{d-icon this.field.icon}}

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
class WizardFieldSerializer < ApplicationSerializer
attributes :id, :type, :required, :value, :label, :placeholder, :description, :extra_description, :icon, :show_in_sidebar
attributes :id, :type, :required, :value, :label, :placeholder, :description, :extra_description, :icon, :disabled, :show_in_sidebar
has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects
def id
@ -75,6 +75,14 @@ class WizardFieldSerializer < ApplicationSerializer
object.icon.present?
end
def disabled
object.disabled
end
def include_disabled?
object.disabled
end
def show_in_sidebar
object.show_in_sidebar
end

View File

@ -16,7 +16,7 @@ class Wizard
end
class Field
attr_reader :id, :type, :required, :value, :icon, :choices, :show_in_sidebar
attr_reader :id, :type, :required, :value, :icon, :choices, :disabled, :show_in_sidebar
attr_accessor :step
def initialize(attrs)
@ -27,6 +27,7 @@ class Wizard
@required = !!attrs[:required]
@value = attrs[:value]
@icon = attrs[:icon]
@disabled = attrs[:disabled]
@choices = []
@show_in_sidebar = attrs[:show_in_sidebar]
end

View File

@ -16,9 +16,12 @@ RSpec.describe Wizard::Step do
dropdown.add_choice('candy')
dropdown.add_choice('nachos', data: { color: 'yellow' })
dropdown.add_choice('pizza', label: 'Pizza!')
expect(step.fields).to eq([text, dropdown])
expect(dropdown.choices.size).to eq(3)
checkbox = step.add_field(id: 'foobar', type: 'checkbox', disabled: true)
expect(step.fields).to eq([text, dropdown, checkbox])
expect(checkbox.disabled).to eq(true)
end
end