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

Fix Input Widget css style and add alternate for Widget-Forms to allow customization #15563

Merged
merged 5 commits into from
Mar 25, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using OrchardCore.ContentManagement;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Descriptors;
using OrchardCore.DisplayManagement.Utilities;
using OrchardCore.Forms.Models;

namespace OrchardCore.Forms;

public class FormShapeTableProvider : IShapeTableProvider
{
public void Discover(ShapeTableBuilder builder)
{
builder.Describe("Widget__Form")
.OnDisplaying(context =>
{
if (context.Shape.TryGetProperty<ContentItem>("ContentItem", out var contentItem)
&& contentItem.TryGet<FormElementPart>(out var elementPart)
&& !string.IsNullOrEmpty(elementPart.Id))
{
context.Shape.Metadata.Alternates.Add($"Widget__{contentItem.ContentType}_{elementPart.Id.EncodeAlternateElement()}");
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Apis.GraphQL.Abstractions\OrchardCore.Apis.GraphQL.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentManagement.Display\OrchardCore.ContentManagement.Display.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement.Abstractions\OrchardCore.DisplayManagement.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Module.Targets\OrchardCore.Module.Targets.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Forms/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.Data.Migration;
using OrchardCore.DisplayManagement.Descriptors;
using OrchardCore.Forms.Activities;
using OrchardCore.Forms.Activities.Drivers;
using OrchardCore.Forms.Drivers;
Expand Down Expand Up @@ -76,6 +77,7 @@ public override void ConfigureServices(IServiceCollection services)
.UseDisplayDriver<FormElementValidationPartDisplayDriver>();

services.AddDataMigration<Migrations>();
services.AddScoped<IShapeTableProvider, FormShapeTableProvider>();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<label asp-for="Type" class="@Orchard.GetLabelClasses()">@T["Type"]</label>
<div class="@Orchard.GetEndClasses()">
<select asp-for="Type" class="form-select content-preview-select">
<option value="submit">Submit</option>
<option value="button">Button</option>
<option value="reset">Reset</option>
<option value="submit">@T["Submit"]</option>
<option value="button">@T["Button"]</option>
<option value="reset">@T["Reset"]</option>
</select>
<span class="hint">@T["The button type."]</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<label asp-for="LabelOption" class="@Orchard.GetLabelClasses()">@T["Label option"]</label>
<div class="@Orchard.GetEndClasses()">
<select asp-for="LabelOption" class="form-select content-preview-select field-label-option-select-menu">
<option value="@LabelOptions.None">@T["None"]</option>
<option value="@LabelOptions.Standard">@T["Standard"]</option>
<option value="@LabelOptions.ScreenReaders">@T["Screen Readers"]</option>
<option value="@nameof(LabelOptions.None)">@T["None"]</option>
<option value="@nameof(LabelOptions.Standard)">@T["Standard"]</option>
<option value="@nameof(LabelOptions.ScreenReaders)">@T["Screen Readers"]</option>
</select>
<span class="hint">@T["The type of label to create for this field."]</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</div>

<script at="Foot">
var initilizeFieldType = (wrapper) => {
var initializeFieldType = (wrapper) => {
var selectMenus = wrapper.getElementsByClassName('field-type-select-menu');
for (let i = 0; i < selectMenus.length; i++) {
var selectMenu = selectMenus[i];
Expand All @@ -74,9 +74,9 @@
};
var wrapper = document.getElementById('@wrapperId')
if (wrapper != null) {
initilizeFieldType(wrapper);
initializeFieldType(wrapper);
}
document.addEventListener('DOMContentLoaded', function () {
initilizeFieldType(document);
initializeFieldType(document);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
var fieldName = formInputElementPart.Name;
var fieldId = !string.IsNullOrEmpty(elementId) ? elementId : !string.IsNullOrEmpty(fieldName) ? Html.GenerateIdFromName(fieldName) : default(string);
var fieldValue = Model.Value.DefaultValue;
var fieldClass = "form-control";
var fieldClass = Model.Value.Type == "checkbox" ? "form-check-input" : "form-control";
Piedone marked this conversation as resolved.
Show resolved Hide resolved
var isChecked = false;

if (ViewData.ModelState.TryGetValue(fieldName, out var fieldEntry))
Expand All @@ -23,9 +23,9 @@

if (fieldEntry.Errors.Count > 0)
{
fieldClass = "form-control input-validation-error is-invalid";
fieldClass += " input-validation-error is-invalid";
}
}
}

<input id="@fieldId" name="@fieldName" type="@Model.Value.Type" class="@fieldClass" value="@fieldValue" placeholder="@Model.Value.Placeholder" @(isChecked ? "checked" : "") />
<input id="@fieldId" name="@fieldName" type="@Model.Value.Type" class="@fieldClass" value="@fieldValue" placeholder="@Model.Value.Placeholder" @(isChecked ? "checked" : string.Empty) />
Loading