Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Search when opening a form.

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Search when opening a form.

Unread post by kknm »

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+')');
kev1n
nuBuilder Team
Posts: 4302
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Search when opening a form.

Unread post by kev1n »

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) 
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: Search when opening a form.

Unread post by kknm »

And if I need to get the same thing on a regular Browse-Form?
kev1n
nuBuilder Team
Posts: 4302
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Search when opening a form.

Unread post by kev1n »

This also works with a normal Browse Form.
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: Search when opening a form.

Unread post by kknm »

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 ...
kev1n
nuBuilder Team
Posts: 4302
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Search when opening a form.

Unread post by kev1n »

Can you show your Browse SQL?
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: Search when opening a form.

Unread post by kknm »

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
kev1n
nuBuilder Team
Posts: 4302
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Search when opening a form.

Unread post by kev1n »

Modify these 2 lines:

Code: Select all

nuAddActionButton('f_month', fMonth, 'nuSearchAction("", '+ tmonth +')');
nuAddActionButton('f_year', year, 'nuSearchAction("", '+ year+ ')');
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: Search when opening a form.

Unread post by kknm »

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?
kev1n
nuBuilder Team
Posts: 4302
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Search when opening a form.

Unread post by kev1n »

Should the form display all records when opened? Then you would this "OR LOCATE( ..." condition in your where clause that I posted earlier.
Post Reply