• Resolved ident85

    (@ident85)


    Dear Community, Dear Authors.

    I would like to set the Datepicker Timerange from
    Current Date – till a maximum of 3 Months from current date.
    is it possible to do this with CMB2 ?

    I have a Vendor shop and use CMB2 for Product Submission,
    within my Functions.php i have set up “hidden non Scheduled Products”

    so the Datepicker will be used to Schedule a Sale Price.
    but i would like to restrict Vendors from setting a Product for more then 3 Months ( in case to serve allways actual Offers to my visitors )

    my current code looks like:

    "name" : "Begin Sale Price",
    "id" : "_sale_price_dates_from",
    "type" : "text_date_timestamp",
    "date_format": "d-m-Y",
    "attributes" : {
    "required" : "required",
    "data-validation" : "required",
    "data-error" : "Please Submit a Start Date"
    },

    AND

    "name" : "End Sale Price",
    "id" : "_sale_price_dates_to",
    "type" : "text_date_timestamp",
    "date_format": "d-m-Y",
    "attributes" : {
    "required" : "required",
    "data-validation" : "required",
    "data-error" : "Please Submit an End Date"
    },

    How can i get what i need?.

    Support is appreciated
    Regards,
    Ident85

    https://ww.wp.xz.cn/plugins/cmb2/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Just spitballin’ for an initial response here, won’t have any code examples or references quite yet (will return to this tomorrow with a more code-based answer).

    Perhaps hook into validation functions for the end sale price timestamp and check the submitted value for if beyond 3 months or so? May be possible to throw an error of some sort, or perhaps do the calculations to be exactly 3 months and force the value at that amount?

    Thread Starter ident85

    (@ident85)

    i dont find any hooks in your Documentation, thats why i get stucked here.

    would be nice if you can submit a code that i can use to archive my request. if it won’t work, im okay with that, but would like to walk on with cmb2 as i really like your plugin.

    i can wait… this is not that urgent.

    Regards
    Ident85

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    There’s not a HUGE amount of do_action/apply_filters hooks but there are some. This library mostly works with function callbacks as field parameters and defaults when none are provided by the use.

    Stay tuned.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If you’re decent with JavaScript, this may prove useful, though you’d need to modify and do the date comparison.

    https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/javascript/cmb2-js-validation-required.php

    Not yet stumbling on a PHP solution. There are sanitization callback functions you can use, but we’d need to somehow fetch the start date, and that’s not guaranteed to be saved yet at that point.

    Thread Starter ident85

    (@ident85)

    Im not familiar with Javascript.

    what exactly will this code do?.

    otherwise: is there a way that i can get current date for the Startdate, and hide this field with the current date as default?
    this will shrink my form for 1 field and could do the job in automode.

    i will think about an other solution for the end date, if there is no way to do this with php.

    thanks for your support.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    As is, it just checks to make sure fields are provided, if I recall right. It would need to be amended to also check the date values for the end date.

    For the other part of your last reply, I believe that will depend on if you have the first field already saved. Otherwise there’s no way to query for it quite yet from the post meta. It’d have potential with custom javascript/jquery to fetch from the input field at that time, but once again that goes back to knowhow there.

    You could perhaps do something with default values for the inputs. I’m also not saying there’s no way to do it with PHP, just a question of how to do it with the data present at any given time.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Any changes with this one ident85?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘How to set Datepicker from current date…’ is closed to new replies.