Date Restriction

QuestionsDate Restriction
Giovanni Luca Bonelli asked 10 years ago

Hi Abu!
I want to prevent new rows adding with date field earlier than yesterday.
Can You explain "how to"?

I try with:

$col["formatoptions"] = array("opts" => array("minDate"=> -1));

Datepicker show only available dates but I have 2 problem:

1- Datepicker doesn't work when I select one of available dates
2- I can manually insert a date without restriction

Thank You.

6 Answers
Abu Ghufran answered 10 years ago

1) Unable to regenerate this issue. It works as expected.
2) Set $col["editoptions"]["readonly"]="readonly"; …. it will make field non-type-able and only work with selection.

Giovanni Luca Bonelli answered 10 years ago

I don't know why, but so rewritten, It works!

$col["formatoptions"][opts]["minDate"]=-1;

giovanni luca bonelli answered 12 months ago

Hi Abu, after few years, now something doesn’t still work.

If I set:

$col[“editoptions”][“readonly”]=”readonly”;

I can’t manually bypass date restriction as I want but actually datepicker doesn’t show

Can you check? Thanks

Abu Ghufran Staff answered 12 months ago

Hello,

I don’t fully understand the issue. You can email me grid code and screenshot or screen recording of the issue to regenerate the case and I’ll be updating you back.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
giovanni luca bonelli answered 11 months ago

Hi Abu, I try to better explane the issue.

First of all, you must know that I’m coding under Laravel

The full code of my column is:

 

        $col3 = array();
        $col3["title"] = "Data";
        $col3["name"] = "data"; 
        $col3["width"] = "20";
        $col3["editable"] = true; // this column is editable
        $col3["editoptions"] = array("size"=>20); // with default display of textbox with size 20
        $col3["editrules"] = array("required"=>true); // required:true(false), number:true(false), minValue:val, maxValue:val
        $col3["formatter"] = "date"; // format as date
        $col3["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d-m-Y');
        //$col3["formatoptions"] = array("opts" => array("minDate"=> -2,"maxDate"=> +1));   //SCRITTO IN QUESTO MODO NON FUNZIONA --> VEDI RIGHE SUCCESSIVE
        if (in_array(Auth::user()->role_id, array("10","20","25","30","35","40","50","60","70","80","90")))  //applicazione della restrizione sull'inserimento data prestazione per utenti basso livello
        //if (($livello_utente==50)or($livello_utente==80)) //ACCESSO OPERATORI DI CANTIERE O DIRETTORE DEI LAVORI (restrizioni sul campo DATA)
              {
                    $col3["formatoptions"]["opts"]["minDate"]=-4;  //opts array can have these options: http://trentrichardson.com/examples/timepicker/#tp-options
                    $col3["formatoptions"]["opts"]["maxDate"]=0;  
               }
        //IMPEDISCE DI MODIFICARE MANUALMENTE LA DATA:  2020 NON FUNZIONA PIU???? 2023 => IN READONLY NON PARTE PIU NEMMENO IL POPUP PER SELEZIONARE LA DATA
        //$col3["editoptions"]["readonly"]="readonly";
        $col3["align"] = "center";
        $cols3[] = $col3;

In this case, minDate and maxDate restriction works on graphic datepicker but anyone can manually edit the text in the box and skip data restriction

If I set as your suggestion:
 $col3["editoptions"]["readonly"]="readonly"; 

no one can skip data restriction but graphic datepicker doesn't appear so I can't pick a data (obiously for a readonly parameter!)

Thanks!
Abu Ghufran Staff answered 10 months ago

I would recommend using server-side validation.

Refer https://www.gridphp.com/demo/demos/editing/server-validation.phps Line 30-50

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

2 + 4 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?