Datepicker !!

10 years ago
i have added a date picker to a product, but only have years 2010 and 2011 availalbe how can i extend the year range

Thanks Steve
10 years ago
Open Modules\ProductAttributes.ascx.cs file and replace
case AttributeControlTypeEnum.Datepicker:
                                {
                                    var datePicker = new NopDatePicker();
                                    //changes these properties in order to change year range
                                    datePicker.FirstYear = DateTime.Now.Year;
                                    datePicker.LastYear = DateTime.Now.Year + 1;
                                    datePicker.ID = controlId;
                                    divAttribute.Controls.Add(datePicker);
                                }

with the following code:
case AttributeControlTypeEnum.Datepicker:
                                {
                                    var datePicker = new NopDatePicker();
                                    //changes these properties in order to change year range
                                    datePicker.FirstYear = YourStartYearHere;
                                    datePicker.LastYear = YourEndYearHere;
                                    datePicker.ID = controlId;
                                    divAttribute.Controls.Add(datePicker);
                                }
10 years ago
Andrei,

obvious when you know how, thank you

Steve
2 years ago
a.m. wrote:
Open Modules\ProductAttributes.ascx.cs file and replace
case AttributeControlTypeEnum.Datepicker:
                                {
                                    var datePicker = new NopDatePicker();
                                    //changes these properties in order to change year range
                                    datePicker.FirstYear = DateTime.Now.Year;
                                    datePicker.LastYear = DateTime.Now.Year + 1;
                                    datePicker.ID = controlId;
                                    divAttribute.Controls.Add(datePicker);
                                }

with the following code:
case AttributeControlTypeEnum.Datepicker:
                                {
                                    var datePicker = new NopDatePicker();
                                    //changes these properties in order to change year range
                                    datePicker.FirstYear = YourStartYearHere;
                                    datePicker.LastYear = YourEndYearHere;
                                    datePicker.ID = controlId;
                                    divAttribute.Controls.Add(datePicker);
                                }



and sir i want only future date i mean the how can i prevent that  customer can not select any past date . tell me the code fr that.
2 years ago
The code shown is for old versions - v4 is done differently
What version you using ?
Do you want all date entry to be future only - for what purpose ?

You can easily not let previous year be selected by removing them from the list
For example in customer registration - Register.cshtml

                    @if (Model.DateOfBirthEnabled)
                    {
                        <div class="inputs date-of-birth">
                            <label>@T("Account.Fields.DateOfBirth"):</label>
                            <nop-date-picker
                                asp-day-name="@Html.NameFor(x => x.DateOfBirthDay)"
                                asp-month-name="@Html.NameFor(x => x.DateOfBirthMonth)"
                                asp-year-name="@Html.NameFor(x => x.DateOfBirthYear)"
                                asp-begin-year="@(DateTime.Now.Year - 110)"

Remove the "- 110"

Also modify Nop.Web.Framework.TagHelpers.Shared : NopDatePickerTagHelper

But previous month and days past is a little harder - I mean they are all still in the list just ordered differently ?

Otherwise you can check the date after entered and display and error if it is in the future

But sure what date you want to future proof ?
2 years ago
Yidna wrote:
The code shown is for old versions - v4 is done differently
What version you using ?
Do you want all date entry to be future only - for what purpose ?

You can easily not let previous year be selected by removing them from the list
For example in customer registration - Register.cshtml

                    @if (Model.DateOfBirthEnabled)
                    {
                        <div class="inputs date-of-birth">
                            <label>@T("Account.Fields.DateOfBirth"):</label>
                            <nop-date-picker
                                asp-day-name="@Html.NameFor(x => x.DateOfBirthDay)"
                                asp-month-name="@Html.NameFor(x => x.DateOfBirthMonth)"
                                asp-year-name="@Html.NameFor(x => x.DateOfBirthYear)"
                                asp-begin-year="@(DateTime.Now.Year - 110)"

Remove the "- 110"

Also modify Nop.Web.Framework.TagHelpers.Shared : NopDatePickerTagHelper

But previous month and days past is a little harder - I mean they are all still in the list just ordered differently ?

Otherwise you can check the date after entered and display and error if it is in the future

But sure what date you want to future proof ?



Sir i am using 3.8 version and i given a product attribute with the name of chose delivery date with date picker id now  i want customer or buyer can only chose a future a date for delivery show how can i add this condition and provide me code and the name of file in which i have to add that code.

thanku sir in advance
2 years ago
Here is some quick throw together code to check your date attribute is in the future
I checked it in v4 so hope it works in v3.8

Note: it's going to check all Datepicker attributes for now

1. Need to allow validation rules for Datepicker attributes

Edit Nop.Services.Catalog : public static class ProductAttributeExtensions

add Datepicker as follows

        public static bool ValidationRulesAllowed(this ProductAttributeMapping productAttributeMapping)
        {
            if (productAttributeMapping == null)
                return false;

            if (productAttributeMapping.AttributeControlType == AttributeControlType.TextBox ||
                productAttributeMapping.AttributeControlType == AttributeControlType.MultilineTextbox ||
                productAttributeMapping.AttributeControlType == AttributeControlType.FileUpload ||
                productAttributeMapping.AttributeControlType == AttributeControlType.Datepicker)
                return true;

            //other attribute controle types does not have validation
            return false;
        }


2. Check the date is in the future

Edit public partial class ShoppingCartService : IShoppingCartService

In public virtual IList<string> GetShoppingCartItemAttributeWarnings(Customer customer,

Under //validation rules

Change

            }

            if (warnings.Any())
                return warnings;

To

                //Datepicker
                if (pam.AttributeControlType == AttributeControlType.Datepicker)
                {
                    var valuesStr = _productAttributeParser.ParseValues(attributesXml, pam.Id);
                    var enteredDate = valuesStr.FirstOrDefault();
                    var convertedDate = DateTime.Parse(enteredDate);
                    var convertedDateUtc = DateTime.SpecifyKind(convertedDate, DateTimeKind.Utc);
                    var now = DateTime.UtcNow;
                    if (convertedDateUtc.CompareTo(now) <= 0)
                        warnings.Add(_localizationService.GetResource("Products.ProductAttributes.DateInFuture"));
                }
            }

            if (warnings.Any())
                return warnings;


3. Create a LocalResourceString

Products.ProductAttributes.DateInFuture "Please enter a date in the future"
2 years ago
Yidna wrote:
Here is some quick throw together code to check your date attribute is in the future
I checked it in v4 so hope it works in v3.8

Note: it's going to check all Datepicker attributes for now

1. Need to allow validation rules for Datepicker attributes

Edit Nop.Services.Catalog : public static class ProductAttributeExtensions

add Datepicker as follows

        public static bool ValidationRulesAllowed(this ProductAttributeMapping productAttributeMapping)
        {
            if (productAttributeMapping == null)
                return false;

            if (productAttributeMapping.AttributeControlType == AttributeControlType.TextBox ||
                productAttributeMapping.AttributeControlType == AttributeControlType.MultilineTextbox ||
                productAttributeMapping.AttributeControlType == AttributeControlType.FileUpload ||
                productAttributeMapping.AttributeControlType == AttributeControlType.Datepicker)
                return true;

            //other attribute controle types does not have validation
            return false;
        }


2. Check the date is in the future

Edit public partial class ShoppingCartService : IShoppingCartService

In public virtual IList<string> GetShoppingCartItemAttributeWarnings(Customer customer,

Under //validation rules

Change

            }

            if (warnings.Any())
                return warnings;

To

                //Datepicker
                if (pam.AttributeControlType == AttributeControlType.Datepicker)
                {
                    var valuesStr = _productAttributeParser.ParseValues(attributesXml, pam.Id);
                    var enteredDate = valuesStr.FirstOrDefault();
                    var convertedDate = DateTime.Parse(enteredDate);
                    var convertedDateUtc = DateTime.SpecifyKind(convertedDate, DateTimeKind.Utc);
                    var now = DateTime.UtcNow;
                    if (convertedDateUtc.CompareTo(now) <= 0)
                        warnings.Add(_localizationService.GetResource("Products.ProductAttributes.DateInFuture"));
                }
            }

            if (warnings.Any())
                return warnings;


3. Create a LocalResourceString

Products.ProductAttributes.DateInFuture "Please enter a date in the future"


vry vry thanku sir its very helpfull for me.