OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.37k stars 2.38k forks source link

Boolean switch unuseable inside flow part #3944

Open Flarescape opened 5 years ago

Flarescape commented 5 years ago

As the title says, the boolean field switch does not work inside a flow part. The switch does nothing on click.

Skrypt commented 5 years ago

A BagPart content item boolean field switch doesn't work. Repro :

screencapture-localhost-44300-Admin-Contents-ContentTypes-Acme-Create-2019-08-09-16_17_17

Here is the rendered Bootstrap switch :

<span class="switch">
        <input type="checkbox" class="switch switch-sm content-preview-select" data-val="true" data-val-required="The Value field is required." id="z99ffbbf8e726edae142ff0bb052f263_Acme2_Active_Value" name="399ffbbf8e726edae142ff0bb052f263.Acme2.Active.Value" value="true">
    <input name="399ffbbf8e726edae142ff0bb052f263.Acme2.Active.Value" type="hidden" value="false">
    <input name="399ffbbf8e726edae142ff0bb052f263.Acme2.Active.Value" type="hidden" value="false">
        <label for="z99ffbbf8e726edae142ff0bb052f263_Acme2_Active_Value">Active</label>
</span>

If I'm removing the 2 hidden inputs that are placed in between the checkbox and it's label then the switch works. So, here the hidden inputs needs to be appended before the checkbox input or after it's label else it breaks the component.

Skrypt commented 5 years ago

I tested the preview here with the predefined lists to make sure it's working with a BagPart and it worked.

sebastienros commented 5 years ago

maybe a conflict when there is another one on the page like in the screenshot?

Skrypt commented 5 years ago

Not related to having an other one. I added it on the main content type to see the difference in the HTML rendered but it was not working for the one in the BagPart before I added the one on the main content type.

Skrypt commented 5 years ago

There is clearly an issue when the hidden inputs are appended since we can see that they are duplicates.

Skrypt commented 5 years ago

Here is the HTML of the main content type one :

<span class="switch">
        <input type="checkbox" class="switch switch-sm content-preview-select" data-val="true" data-val-required="The Value field is required." id="Acme_Active_Value" name="Acme.Active.Value" value="true">
        <label for="Acme_Active_Value">Active</label>
</span>

No hidden input required for this one. So it might be an issue with the preview script or the FlowPart script.

Skrypt commented 5 years ago

It's not coming from the contentpreview.edit.js.

agriffard commented 4 years ago

When you add in a Form a widget that has a BooleanField, it adds 2 hidden input. Ex:

<span class="switch">
        <input type="checkbox" class="switch switch-sm content-preview-select" data-val="true" data-val-required="The Value field is required." id="z059826f467d4e1dab99b79ae8c02b67_RichContent_Visible_Value" name="2059826f467d4e1dab99b79ae8c02b67.RichContent.Visible.Value" value="true">
<input name="2059826f467d4e1dab99b79ae8c02b67.RichContent.Visible.Value" type="hidden" value="false">
<input name="2059826f467d4e1dab99b79ae8c02b67.RichContent.Visible.Value" type="hidden" value="false">
        <label for="z059826f467d4e1dab99b79ae8c02b67_RichContent_Visible_Value">Visible</label>
    </span> 

If the field is using a switch Editor, it prevents to switch the property after the widget is added.

When it is saved and reedited, the 2 inputs don't appear anymore and it works.

sebastienros commented 4 years ago

Can we check that this line is not generated twice also in a standard editor?