Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate admin required fields #15545

Merged
merged 6 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,15 @@
"contributions": [
"code"
]
},
{
"login": "xtomas",
"name": "Tomáš Jákl",
"avatar_url": "https://avatars.githubusercontent.com/u/10938220?v=4",
"profile": "https://github.com/xtomas",
"contributions": [
"code"
]
}
],
"skipCi": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<div class="autoroute-disabled" style="@(Model.Disabled ? "display: none" : string.Empty)">
<div class="@Orchard.GetWrapperClasses()" asp-validation-class-for="Path">
<label asp-for="Path" class="@Orchard.GetLabelClasses()">@T["Permalink"]</label>
<label asp-for="Path" class="@Orchard.GetLabelClasses(inputRequired: true)">@T["Permalink"]</label>
<div class="@Orchard.GetEndClasses()">
<div class="input-group">
@if (!string.IsNullOrWhiteSpace(site.BaseUrl))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override async Task<IDisplayResult> UpdateAsync(NumericField field, IUpda
{
if (settings.Required)
{
updater.ModelState.AddModelError(Prefix, nameof(field.Value), S["The {0} field is required.", context.PartFieldDefinition.DisplayName()]);
updater.ModelState.AddModelError(Prefix, nameof(field.Value), S["A value is required for {0}.", context.PartFieldDefinition.DisplayName()]);
}
}
else if (!decimal.TryParse(viewModel.Value, NumberStyles.Any, CultureInfo.CurrentUICulture, out var value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override async Task<IDisplayResult> UpdateAsync(UserPickerField field, IU

if (settings.Required && field.UserIds.Length == 0)
{
updater.ModelState.AddModelError(Prefix, nameof(field.UserIds), S["The {0} field is required.", context.PartFieldDefinition.DisplayName()]);
updater.ModelState.AddModelError(Prefix, nameof(field.UserIds), S["The value is required for {0}.", context.PartFieldDefinition.DisplayName()]);
}

if (!settings.Multiple && field.UserIds.Length > 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override async Task<IDisplayResult> UpdateAsync(YoutubeField field, IUpda
var settings = context.PartFieldDefinition.GetSettings<YoutubeFieldSettings>();
if (settings.Required && string.IsNullOrWhiteSpace(model.RawAddress))
{
updater.ModelState.AddModelError(Prefix, nameof(model.RawAddress), S["A value is required for '{0}'.", context.PartFieldDefinition.DisplayName()]);
updater.ModelState.AddModelError(Prefix, nameof(model.RawAddress), S["A value is required for {0}.", context.PartFieldDefinition.DisplayName()]);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<style asp-name="vue-multiselect" at="Foot"></style>

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.ContentItemIds)_FieldWrapper">
<label asp-for="ContentItemIds" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="ContentItemIds" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<div id="@vueElementId" class="vue-multiselect" data-part="@partName" data-field="@fieldName" data-editor-type="ContentPicker" data-selected-items="@selectedItems" data-search-url="@searchUrl" data-multiple="@multiple">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
}

<div class="@Orchard.GetWrapperClasses()">
<label asp-for="Value" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="Value" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<div class="@Orchard.GetLimitedWidthWrapperClasses()">
<div class="@Orchard.GetLimitedWidthClasses()">
<input asp-for="Value" type="text" class="form-control content-preview-select datepicker" required="@settings.Required" />
<input asp-for="Value" type="text" class="form-control content-preview-select datepicker" />
<span asp-validation-for="Value"></span>
</div>
</div>
@if (!string.IsNullOrEmpty(settings.Hint))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

<script asp-name="jQuery-ui-i18n" at="Foot"></script>
<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Value)_FieldWrapper">
Copy link
Contributor

@Skrypt Skrypt Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried with asp-validation-class-for="Value" on this div to set the entire "field" to be set has having a validation error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

image

<label asp-for="Value" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="Value" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<div class="@Orchard.GetLimitedWidthWrapperClasses()">
<div class="@Orchard.GetLimitedWidthClasses()">
<input asp-for="Value" type="date" class="form-control content-preview-select" required="@settings.Required" />
<input asp-for="Value" type="date" class="form-control content-preview-select" />
<span asp-validation-for="Value"></span>
</div>
</div>
@if (!string.IsNullOrEmpty(settings.Hint))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
}
<script asp-name="jQuery-ui-i18n" at="Foot"></script>
<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.LocalDateTime)_FieldWrapper">
<label asp-for="LocalDateTime" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="LocalDateTime" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<div class="@Orchard.GetLimitedWidthWrapperClasses()">
<div class="@Orchard.GetLimitedWidthClasses()">
<input asp-for="LocalDateTime" type="datetime-local" class="form-control content-preview-select" required="@settings.Required" />
<input asp-for="LocalDateTime" type="datetime-local" class="form-control content-preview-select" />
<span asp-validation-for="LocalDateTime"></span>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
@{
var settings = Model.PartFieldDefinition.GetSettings<LinkFieldSettings>();
var isRequired = settings.Required && string.IsNullOrWhiteSpace(settings.DefaultUrl);
var isTextRequired = settings.LinkTextMode == LinkTextMode.Required && string.IsNullOrWhiteSpace(settings.DefaultText);
var urlClass = settings.Required ? "required" : null;
var textClass = settings.LinkTextMode == LinkTextMode.Required ? "required" : null;
var useFormFloating = string.IsNullOrWhiteSpace(settings.UrlPlaceholder) || string.IsNullOrWhiteSpace(settings.TextPlaceholder);
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Text)_FieldWrapper">
<label asp-for="Url" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="Url" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<div class="row">
<div class="col-md-6" asp-validation-class-for="Url">
<div class="@(useFormFloating ? "form-floating" : string.Empty)">
<input asp-for="Url" class="form-control content-preview-text" placeholder="@settings.UrlPlaceholder" required="@isRequired" />
<input asp-for="Url" class="form-control content-preview-text" placeholder="@settings.UrlPlaceholder" />
<span asp-validation-for="Url"></span>
@if (useFormFloating)
{
<label asp-for="Url" class="@urlClass">@T["Url"]</label>
Expand All @@ -31,7 +31,7 @@
{
<div class="col-md-6" asp-validation-class-for="Text">
<div class="@(useFormFloating ? "form-floating" : string.Empty)">
<input asp-for="Text" type="text" class="form-control content-preview-text" placeholder="@settings.TextPlaceholder" required="@isTextRequired" />
<input asp-for="Text" type="text" class="form-control content-preview-text" placeholder="@settings.TextPlaceholder" />
@if (useFormFloating)
{
<label asp-for="Text" class="@textClass">@T["Link text"]</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<style asp-name="vue-multiselect" at="Foot"></style>

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.LocalizationSets)_FieldWrapper">
<label asp-for="LocalizationSets" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="LocalizationSets" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<div id="@vueElementId" class="vue-multiselect" data-part="@partName" data-field="@fieldName" data-editor-type="LocalizationSetContentPicker" data-selected-items="@selectedItems" data-search-url="@searchUrl" data-multiple="@multiple">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Values)_FieldWrapper">
<label class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
@for (int i = 0; i < options.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<style asp-name="vue-multiselect" at="Foot"></style>

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Values)_FieldWrapper">
<label class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<div id="@vueElementId" class="multitextfieldpicker" data-selectedvalues="@jSelectedValues" data-options="@jOptions" data-valueskey="@valuesKey">
<div class="w-xl-50">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Values)_FieldWrapper">
<label asp-for="Values" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="Values" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<select class="form-select content-preview-select" asp-for="Values" asp-items="options" multiple></select>
<span asp-validation-for="Values"></span>
@if (!string.IsNullOrEmpty(settings.Hint))
{
<span class="hint">@settings.Hint</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Value)_FieldWrapper">
<label asp-for="Value" class="@Orchard.GetLabelClasses()">@name</label>
<label asp-for="Value" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@name</label>
<div class="@Orchard.GetEndClasses()">
<div class="@Orchard.GetLimitedWidthWrapperClasses()">
<div class="@Orchard.GetLimitedWidthClasses()">
Expand All @@ -22,13 +22,14 @@
{
<span class="input-group-text">@min</span>
}
<input asp-for="Value" class="form-control content-preview-select" placeholder="@settings.Placeholder" required="@settings.Required" onchange="numericFieldRangeSync('@(id)-range', value);" />
<input asp-for="Value" class="form-control content-preview-select" placeholder="@settings.Placeholder" onchange="numericFieldRangeSync('@(id)-range', value);" />
@if (settings.Maximum.HasValue)
{
<span class="input-group-text">@max</span>
}
</div>
<input id="@(id)-range" class="form-control-range" type="range" min="@min" max="@max" step="@step" oninput="numericFieldRange('@(id)', value);" onchange="numericFieldRange('@(id)', value);" />
<span asp-validation-for="Value"></span>
</div>
</div>
@if (!string.IsNullOrEmpty(settings.Hint))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Value)_FieldWrapper">
<label asp-for="Value" class="@Orchard.GetLabelClasses()">@name</label>
<label asp-for="Value" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@name</label>
<div class="@Orchard.GetEndClasses()">

<select asp-for="Value" class="form-select content-preview-select">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<script asp-name="nouislider" at="Foot"></script>

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Value)_FieldWrapper">
<label asp-for="Value" class="@Orchard.GetLabelClasses()">@name</label>
<label asp-for="Value" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@name</label>
<div class="@Orchard.GetEndClasses()">
<div class="@Orchard.GetLimitedWidthWrapperClasses()">
<div class="@Orchard.GetLimitedWidthClasses()">
Expand All @@ -24,7 +24,7 @@
{
<span class="input-group-text">@min</span>
}
<input asp-for="Value" class="form-control content-preview-select" placeholder="@settings.Placeholder" required="@settings.Required" />
<input asp-for="Value" class="form-control content-preview-select" placeholder="@settings.Placeholder" />
@if (settings.Maximum.HasValue)
{
<span class="input-group-text">@max</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Value)_FieldWrapper">
<label asp-for="Value" class="@Orchard.GetLabelClasses()">@name</label>
<label asp-for="Value" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@name</label>
<div class="@Orchard.GetEndClasses()">
<div class="@Orchard.GetLimitedWidthWrapperClasses()">
<div class="@Orchard.GetLimitedWidthClasses()">
Expand All @@ -25,7 +25,7 @@
{
<span class="input-group-text">@min</span>
}
<input asp-for="Value" typeof="text" class="form-control content-preview-select" placeholder="@settings.Placeholder" required="@settings.Required" />
<input asp-for="Value" typeof="text" class="form-control content-preview-select" placeholder="@settings.Placeholder" />
<button class="btn btn-outline-secondary" type="button" onclick="numericFieldSpinner('@(id)', @(scale), -@(step), @(min), @(max))"><i class="fa-solid fa-minus" aria-hidden="true"></i></button>
<button class="btn btn-outline-secondary" type="button" onclick="numericFieldSpinner('@(id)', @(scale), +@(step), @(min), @(max))"><i class="fa-solid fa-plus" aria-hidden="true"></i></button>
@if (settings.Maximum.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Value)_FieldWrapper">
<label asp-for="Value" class="@Orchard.GetLabelClasses()">@name</label>
<label asp-for="Value" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@name</label>
<div class="@Orchard.GetEndClasses()">
<div class="@Orchard.GetLimitedWidthWrapperClasses()">
<div class="@Orchard.GetLimitedWidthClasses()">
Expand All @@ -17,12 +17,13 @@
{
<span class="input-group-text">@min</span>
}
<input asp-for="Value" class="form-control content-preview-select" placeholder="@settings.Placeholder" required="@settings.Required" />
<input asp-for="Value" class="form-control content-preview-select" placeholder="@settings.Placeholder" />
@if (settings.Maximum.HasValue)
{
<span class="input-group-text">@max</span>
}
</div>
<span asp-validation-for="Value"></span>
</div>
</div>
@if (!string.IsNullOrEmpty(settings.Hint))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Text)_FieldWrapper">
<label asp-for="Text" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="Text" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<textarea asp-for="Text" rows="5" class="form-control content-preview-text" dir="@culture.GetLanguageDirection()"></textarea>
<span asp-validation-for="Text"></span>
@if (!string.IsNullOrEmpty(settings.Hint))
{
<span class="hint">@settings.Hint</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Text)_FieldWrapper">
<label asp-for="Text" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="Text" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses("pt-lg-2")">
<input asp-for="Text" class="form-control content-preview-text" type="color" style="min-height: 2.25rem" />
<span asp-validation-for="Text"></span>
@if (!string.IsNullOrEmpty(settings.Hint))
{
<span class="hint">@settings.Hint</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
}

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Text)_FieldWrapper">
<label asp-for="Text" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="Text" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<div class="input-group">
<span class="input-group-text">@@</span>
<input asp-for="Text" class="form-control content-preview-text" type="email" />
<span asp-validation-for="Text"></span>
</div>
@if (!string.IsNullOrEmpty(settings.Hint))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script asp-name="iconpickerCustomScript" asp-src="~/OrchardCore.ContentFields/Scripts/iconpicker-custom.js" at="Foot"></script>

<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Text)_FieldWrapper">
<label asp-for="Text" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<label asp-for="Text" class="@Orchard.GetLabelClasses(inputRequired: settings.Required)">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<input type="hidden" asp-for="Text" id="@Html.IdFor(m=>m.Text)" />
<div class="btn-toolbar" role="toolbar" aria-label="Icon Selector Toolbar">
Expand All @@ -25,6 +25,7 @@
<div class="dropdown-menu"></div>
</div>
</div>
<span asp-validation-for="Text"></span>

@if (!string.IsNullOrEmpty(settings.Hint))
{
Expand Down
Loading
Loading