Jump to content

UniDateTimePicker - how to clear DisabledDates array in runtime?


Nadya

Recommended Posts

Hello!

I have a UniDateTimePicker on form. MinDate, MaxDate and DisableDates are calculated dynamically from database depending on selected year.

And there is a trouble - once DisabledDates is set I don't know how to clear it when it's nesessary. I've made a test project in which follow actions should be done:

1. Select 2019 in field "Year", press "RestrictDates" button. Result: MinDate = 15.01.2019, maxDate = 13.12.2019, some dates are disabled (including 07.12.2019, 08.12.2019,10.12.2019), current value = 13.12.2019

2. Select 2020 in field "Year", press "RestrictDates" button. Result: MinDate = 01.01.2020, maxDate = current date, some dates are disabled (including 31.07.2020,01.08.2020,02.08.2020), current value = current date

3. Select 2021 in field "Year", press "RestrictDates" button.

Expectable result: MinDate, MaxDate are not restricted, no dates disabled, current value = 01.01.2021. Fact result: All dates are disabled, current date highlited as invalid

https://drive.google.com/file/d/1odvEb8uklcPRvNWUMP7zgosBACcsw3aA/view?usp=sharing

I've tried several ways to clear disabled dates
 

    UniSession.AddJS(dePaymentDate.JSName + '.setDisabledDates(null);'); // No effect

    UniSession.AddJS(dePaymentDate.JSName + '.setDisabledDates([]);'); // No effect

    UniSession.AddJS(dePaymentDate.JSName + '.setDisabledDates(['''']);'); // All dates are disables

    UniSession.AddJS(dePaymentDate.JSName + '.setDisabledDates('''');'); // All dates are disables

Please, tell me, what I've done wrong?

Thank you for advance!

 

Link to comment
Share on other sites

2 hours ago, Nadya said:

I've tried several ways to clear disabled dates

Hi Nadya, 

You can try this code:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniDateTimePicker1.JSInterface.JSCode(#1'.setDisabledDates([null]);');
end;

 

Link to comment
Share on other sites

2 hours ago, Sherzod said:

You can try this code:


procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniDateTimePicker1.JSInterface.JSCode(#1'.setDisabledDates([null]);');
end;

I've tried it and I've got this error:

Config Option: O27->O27.setDisabledDates([null])<br/>is refering a previous request,<br/>it's not allowed in AJAX request or JS handler.<br/>Use equivalent Public Property or Method instead.

Then I've changed code this way:

UniSession.AddJS(dePaymentDates.JSName + '.setDisabledDates([null]);');

And it works, thank you!

Link to comment
Share on other sites

16 minutes ago, Nadya said:

I've tried it and I've got this error:

Config Option: O27->O27.setDisabledDates([null])<br/>is refering a previous request,<br/>it's not allowed in AJAX request or JS handler.<br/>Use equivalent Public Property or Method instead.

Seems, you missed ; at the end

Link to comment
Share on other sites

4 minutes ago, Nadya said:

It helps!!

So sad, but it works only on test project. :-(

"dePaymentsDates" UniDateTimePicker component for test project was copied from main one. Code in main project contains following logic:

first I clear minDate, maxDate values and DisabledDates, thenI get new Min, Max dates and DisabledDates array from database and apply it.

I know that Sencha docs say it's not nesessary to clear array, if you need to set new values. But if I simply replace old array by new one - dates didn't changed.

So I've decided to clear disabledDateds before setting new values. And in test project is works, but in main project - it doesn't. May it be because of some form, ServerModule or MainModule settings?

Link to comment
Share on other sites

36 minutes ago, Sherzod said:

Do you see any errors in the browser console?

Only WARN message:

image.thumb.png.ac77d3231ee6f4f54bb856e975f3f554.png

But I've accidentally found one thing - if I add a call of

UniSession.Synchronize();

in the beginning of method which recalculating and setting date restrictions - it works correctly. When I remove Synchronize call - the behaviour of method returns to those I described ealier.

Link to comment
Share on other sites

40 minutes ago, Nadya said:

But I've accidentally found one thing - if I add a call of


UniSession.Synchronize();

in the beginning of method which recalculating and setting date restrictions - it works correctly. When I remove Synchronize call - the behaviour of method returns to those I described ealier.

Would it be correct to use Synchonize this way?  And PLEASE tell me about this method, when it should or should not be used, and how to use parameters correctly? I've asked about it here on forum but didn't get answer unfortunately...

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...