Search code examples
asp.net-mvc-3razoreditororchardcmsdatetimepicker

How to use DateTimePicker control for datetime field in Orchard editor (without adding datetimefieldpart)?


I know there is DateTime field builtin Orchard and i know i can use it by adding DataTimeFieldPart to the my custom part. But my datetime fields belongs to an "event part record" entity and i want them stored in one table. The problem i faced is the editor view for custom part - my datetime property renders as a text input but i expect it renders like jquery timepicker or input with datetime type at least.

Is it neccesary to add all datetime properties like a separate DateTime parts? As i see, the only way i can use datetime picker it's manually add it to the editors view. For me it's strange because Orchard provides datetime picker functionality in datetime part.

I think i'm missing some idealogic conserns.

        //Event Type
        SchemaBuilder.CreateTable("EventPartRecord",
            table => table
                .ContentPartRecord()
                .Column<string>("Name")
                .Column<DateTime>("StartDateTime")
                .Column<DateTime>("PlanedEndDateTime", c=>c.Nullable())
                .Column<DateTime>("EndDateTime", c => c.Nullable())
                .Column<string>("EventRules")
                .Column<string>("Comment")
                .Column<bool>("IsFinished")
                .Column<int>("CompetitionPartRecord_Id")
            );

        ContentDefinitionManager.AlterPartDefinition("EventPart",
            builder => builder.Attachable()
                .WithField("Competitors",f => f
                .OfType("ContentPickerField")
                .WithSetting("Multiple","true"))
                );

Here is my editors view:

    <div class="editor-label">
        @Html.LabelFor(model => model.PlanedEndDateTime)
    </div>
<div class="editor-field">
    @Html.EditorFor(model => model.PlanedEndDateTime)
    @Html.ValidationMessageFor(model => model.PlanedEndDateTime)
</div>

Solution

  • It is not necessary or even possible to add all datetime properties as parts: only one part of a given type can exist on a type. You could do it through fields however.

    What you need to do in order to reproduce the UI of the date field in your own part is to reproduce the template and script that they use, in your own part templates.