mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
UX: Add required indicator to fields with required
validation (#22096)
This commit is contained in:
@ -7,5 +7,8 @@
|
|||||||
required={{if @validations.required "required" ""}}
|
required={{if @validations.required "required" ""}}
|
||||||
/>
|
/>
|
||||||
{{@attributes.label}}
|
{{@attributes.label}}
|
||||||
|
{{#if @validations.required}}
|
||||||
|
{{d-icon "asterisk" class="form-template-field__required-indicator"}}
|
||||||
|
{{/if}}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
@ -1,6 +1,11 @@
|
|||||||
<div class="control-group form-template-field" data-field-type="dropdown">
|
<div class="control-group form-template-field" data-field-type="dropdown">
|
||||||
{{#if @attributes.label}}
|
{{#if @attributes.label}}
|
||||||
<label class="form-template-field__label">{{@attributes.label}}</label>
|
<label class="form-template-field__label">
|
||||||
|
{{@attributes.label}}
|
||||||
|
{{#if @validations.required}}
|
||||||
|
{{d-icon "asterisk" class="form-template-field__required-indicator"}}
|
||||||
|
{{/if}}
|
||||||
|
</label>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{! TODO(@keegan): Update implementation to use <ComboBox/> instead }}
|
{{! TODO(@keegan): Update implementation to use <ComboBox/> instead }}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
<div class="control-group form-template-field" data-field-type="input">
|
<div class="control-group form-template-field" data-field-type="input">
|
||||||
{{! TODO(@keegan): Make label required }}
|
|
||||||
{{#if @attributes.label}}
|
{{#if @attributes.label}}
|
||||||
<label class="form-template-field__label">{{@attributes.label}}</label>
|
<label class="form-template-field__label">
|
||||||
|
{{@attributes.label}}
|
||||||
|
{{#if @validations.required}}
|
||||||
|
{{d-icon "asterisk" class="form-template-field__required-indicator"}}
|
||||||
|
{{/if}}
|
||||||
|
</label>
|
||||||
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
<div class="control-group form-template-field" data-field-type="multi-select">
|
<div class="control-group form-template-field" data-field-type="multi-select">
|
||||||
{{#if @attributes.label}}
|
{{#if @attributes.label}}
|
||||||
<label class="form-template-field__label">{{@attributes.label}}</label>
|
<label class="form-template-field__label">
|
||||||
|
{{@attributes.label}}
|
||||||
|
{{#if @validations.required}}
|
||||||
|
{{d-icon "asterisk" class="form-template-field__required-indicator"}}
|
||||||
|
{{/if}}
|
||||||
|
</label>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{! TODO(@keegan): Update implementation to use <MultiSelect/> instead }}
|
{{! TODO(@keegan): Update implementation to use <MultiSelect/> instead }}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
<div class="control-group form-template-field" data-field-type="textarea">
|
<div class="control-group form-template-field" data-field-type="textarea">
|
||||||
{{#if @attributes.label}}
|
{{#if @attributes.label}}
|
||||||
<label class="form-template-field__label">{{@attributes.label}}</label>
|
<label class="form-template-field__label">
|
||||||
|
{{@attributes.label}}
|
||||||
|
{{#if @validations.required}}
|
||||||
|
{{d-icon "asterisk" class="form-template-field__required-indicator"}}
|
||||||
|
{{/if}}
|
||||||
|
</label>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<Textarea
|
<Textarea
|
||||||
name={{@attributes.label}}
|
name={{@attributes.label}}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
<div class="control-group form-template-field" data-field-type="upload">
|
<div class="control-group form-template-field" data-field-type="upload">
|
||||||
{{#if @attributes.label}}
|
{{#if @attributes.label}}
|
||||||
<label class="form-template-field__label">{{@attributes.label}}</label>
|
<label class="form-template-field__label">
|
||||||
|
{{@attributes.label}}
|
||||||
|
{{#if @validations.required}}
|
||||||
|
{{d-icon "asterisk" class="form-template-field__required-indicator"}}
|
||||||
|
{{/if}}
|
||||||
|
</label>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
|
@ -13,4 +13,11 @@
|
|||||||
padding: 0.5em 0.65em;
|
padding: 0.5em 0.65em;
|
||||||
font-size: var(--font-0);
|
font-size: var(--font-0);
|
||||||
}
|
}
|
||||||
|
// END of what should be removed after updating dropdown/multi-select to use select-kit
|
||||||
|
|
||||||
|
&__required-indicator {
|
||||||
|
color: var(--danger);
|
||||||
|
margin-left: 0.5em;
|
||||||
|
font-size: var(--font-down-4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,12 @@ describe "Composer Form Template Validations", type: :system, js: true do
|
|||||||
sign_in user
|
sign_in user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "shows an asterisk on the label of the required fields" do
|
||||||
|
category_page.visit(category_with_template)
|
||||||
|
category_page.new_topic_button.click
|
||||||
|
expect(composer).to have_form_template_field_required_indicator("input")
|
||||||
|
end
|
||||||
|
|
||||||
it "shows an error when a required input is not filled in" do
|
it "shows an error when a required input is not filled in" do
|
||||||
category_page.visit(category_with_template)
|
category_page.visit(category_with_template)
|
||||||
category_page.new_topic_button.click
|
category_page.new_topic_button.click
|
||||||
|
@ -142,6 +142,12 @@ module PageObjects
|
|||||||
page.has_css?(".form-template-field[data-field-type='#{field}']")
|
page.has_css?(".form-template-field[data-field-type='#{field}']")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_form_template_field_required_indicator?(field)
|
||||||
|
page.has_css?(
|
||||||
|
".form-template-field[data-field-type='#{field}'] .form-template-field__required-indicator",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
FORM_TEMPLATE_CHOOSER_SELECTOR = ".composer-select-form-template"
|
FORM_TEMPLATE_CHOOSER_SELECTOR = ".composer-select-form-template"
|
||||||
|
|
||||||
def has_no_form_template_chooser?
|
def has_no_form_template_chooser?
|
||||||
|
Reference in New Issue
Block a user