Search when opening a form.

Questions related to customising nuBuilder Forte with JavaScript or PHP.

Search when opening a form.

Unread postby kknm » Thu Apr 22, 2021 6:51 pm

The form has RUN :: iFrame.
I added two buttons to it for searching by a range of dates (for the current month and the current year)
It is necessary to select the reflection by month when opening the form.
Code: Select all
nuAddActionButton('f_month', fMonth, 'nuSearchAction("",'+ year+'.'+month+')');   
   nuAddActionButton('f_year', year, 'nuSearchAction("",'+ year+')');
kknm
 
Posts: 226
Joined: Sat Apr 11, 2020 7:33 am

Re: Search when opening a form.

Unread postby kev1n » Thu Apr 22, 2021 6:57 pm

Set a Hash Cookie with nuSetProperty() before performing the search

Code: Select all
nuSetProperty('year_filter', year)


and use that in your Browse SQL.

Code: Select all
WHERE (YEAR(your_date) = #year_filter# OR LOCATE('#', '#year_filter#') = 1)
kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Search when opening a form.

Unread postby kknm » Thu Apr 22, 2021 9:10 pm

And if I need to get the same thing on a regular Browse-Form?
kknm
 
Posts: 226
Joined: Sat Apr 11, 2020 7:33 am

Re: Search when opening a form.

Unread postby kev1n » Thu Apr 22, 2021 9:13 pm

This also works with a normal Browse Form.
kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Search when opening a form.

Unread postby kknm » Thu Apr 22, 2021 10:16 pm

Code: Select all
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (p_dat LIKE '2021') AND ( (CONVERT(p_dat USING utf8) LIKE "%2021%" OR CONV' at line 3

===SQL===========

SELECT pl_id,p_dat,p_pl,p_dop,p_com,p_dep,p_st
FROM     plan
  WHERE   WHERE (p_dat LIKE '2021') AND ( (CONVERT(p_dat USING utf8) LIKE "%2021%" OR CONVERT(p_pl USING utf8) LIKE "%2021%" OR CONVERT(p_dop USING utf8) LIKE "%2021%" OR CONVERT(p_com USING utf8) LIKE "%2021%" OR CONVERT(p_dep USING utf8) LIKE "%2021%" OR CONVERT(p_st USING utf8) LIKE "%2021%") ) LIMIT 0, 15

Doesn't work in Browse-Form ...
kknm
 
Posts: 226
Joined: Sat Apr 11, 2020 7:33 am

Re: Search when opening a form.

Unread postby kev1n » Thu Apr 22, 2021 11:19 pm

Can you show your Browse SQL?
kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Search when opening a form.

Unread postby kknm » Thu Apr 22, 2021 11:54 pm

Code: Select all
if(nuFormType() == 'browse'){
   
    Data = new Date();
    year = Data.getFullYear();
    month = Data.getMonth();
//    day = Data.getDate();
switch (month)
{
  case 0: fMonth="январь"; break;
  case 1: fMonth="февраль"; break;
  case 2: fMonth="март"; break;
  case 3: fMonth="апрель"; break;
  case 4: fMonth="май"; break;
  case 5: fMonth="июнь"; break;
  case 6: fMonth="июль"; break;
  case 7: fMonth="август"; break;
  case 8: fMonth="сентябрь"; break;
  case 9: fMonth="октябрь"; break;
  case 10: fMonth="ноябрь"; break;
  case 11: fMonth="декабрь"; break;
}
let formDate = Data.toISOString();
tmonth=formDate.substr(0,7);
//nuMessage([tmonth]);
nuSetProperty('year_filter',tmonth);
   
   nuAddActionButton('f_month', fMonth, 'nuSearchAction("", tmonth)');
   nuAddActionButton('f_year', year, 'nuSearchAction("", year)');
}
This is how button search works. But when opened, the form is empty.
My SQL-code
Code: Select all
SELECT
plan.*
FROM
    plan
WHERE
    (( DATE_FORMAT(p_dat,'%Y-%m')  LIKE '#year_filter#'))

no errors
kknm
 
Posts: 226
Joined: Sat Apr 11, 2020 7:33 am

Re: Search when opening a form.

Unread postby kev1n » Fri Apr 23, 2021 12:10 am

Modify these 2 lines:

Code: Select all
nuAddActionButton('f_month', fMonth, 'nuSearchAction("", '+ tmonth +')');
nuAddActionButton('f_year', year, 'nuSearchAction("", '+ year+ ')');
kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Search when opening a form.

Unread postby kknm » Fri Apr 23, 2021 5:05 pm

It doesn't work either.
If we apply nuGetBreadcrumb (0), then the filter is triggered when the form is loaded, but the form is constantly updated. We need to apply nuGetBreadcrumb (0); Just once - how to do it?
kknm
 
Posts: 226
Joined: Sat Apr 11, 2020 7:33 am

Re: Search when opening a form.

Unread postby kev1n » Fri Apr 23, 2021 11:35 pm

Should the form display all records when opened? Then you would this "OR LOCATE( ..." condition in your where clause that I posted earlier.
kev1n
nuBuilder Team
 
Posts: 2012
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Next

Return to Custom Code

Who is online

Users browsing this forum: No registered users and 4 guests

cron