farshaddavoudi / Blazor.PersianDatePicker

A Jalali (Persian) and Gregorian (Miladi) dual datepicker library for Blazor applications
MIT License
64 stars 13 forks source link

onchange not wotk in edit form #77

Open EsmaeelAmarloo opened 11 months ago

EsmaeelAmarloo commented 11 months ago

Hi .when i use datepicker in editform tag "onChange" not work

sample Code

<EditForm Model="TmpModel">
    <InputPersianDatePicker Id="List_Persin_Date11"
    Visible="true"
    Disabled="false"
    PickerAlign="Align.Right"
    PickerOffsetTopPositionInPixels="1"
    InitialValueSetOnToday="false"
    Value ="@strDate"
    CalendarType="Calendar.SingleModeJalali"
    DigitType="DigitType.English"
    DateFormat="DateFormat.yyyy_slash_MM_slash_dd"
    MinDateSetOnToday="false"
    Placeholder="مستقیم"
    CssClass="form-control mt-n3"
    Theme="PickerTheme.Default"
         OnChange="valueChanged"
    ReadOnly="false" />
</EditForm>
farshaddavoudi commented 11 months ago

Hi, thanks for contributing to the project and sharing the issue.

I'll take a look at this, but by saying the OnChange event not working, I'm assuming it won't fire at-all. Correct me if I'm wrong

farshaddavoudi commented 11 months ago

I think your problem will resolve if you use bind-Value ="@strDate" instead of Value ="@strDate" in the component declaration. It's related to the Blazor concept, not my implementation and/or the EditForm component.

If you only need to set the initial value of a property, use Value="@MyVariable". If you want a two-way binding, allowing changes in the variable to automatically update the property and vice versa, use bind-Value="@MyVariable".

Please check it out and update me with the result.

EsmaeelAmarloo commented 11 months ago

i use dateOnly in my project then i cant bind it to string Type parameter.I create wrapper component for persianDatePicker with dateOnly parameter. for tow way binding for wrapper component, I need to handle "onchane" event in "persianDatePicker".

farshaddavoudi commented 10 months ago

I'm a little bit confused. The question is does the datepicker's OnChange work when the bind type is a variable of string type?

Assuming that's true, I think the best approach for you is using a helper string type property to bind to the datepicker and use that string variable and somehow get your primary DateOnly variable from that. I think depending on your project, you can use getter and setters for it or just convert the string to DateOnly when needed for example in Submit button. Sync the main DateOnly property with the helper string type property in the OnChange event can be an option, too.

Please let me know if you have further queries about my suggested approaches.