Page 1 of 1
Search-form with lots of boolean fields
Posted: Fri Nov 11, 2022 3:50 pm
by hame
Hi,
I want to realize a small adress system to manage all the numerous adresses of the office and maybe actions related to the contact (e.g. calls, mails infos). Each address has a lot of fields (boolean) that describe diverse informations (e.g. owns a hotel, owns a restaurant etc.). I'm not sure how to make a very simple form that allows to find specific adresses by selecting some of the named criteria by just clicking/selecting the respective boxes and then "click on find" ...
Thx
Harald
Re: Search-form with lots of boolean fields
Posted: Fri Nov 11, 2022 3:56 pm
by kev1n
I have done something similar just recently
I used a Launch form and placed some filter objects on the left and the results are shown in an embedded iFrame. Did you think of something like this?
search_form.png
Re: Search-form with lots of boolean fields
Posted: Fri Nov 11, 2022 4:58 pm
by miasoft
Yes, it would be nice to have such a Query-form. Or use an already existing Edit-form in Query mode
Re: Search-form with lots of boolean fields
Posted: Sat Nov 12, 2022 1:16 pm
by hame
kev1n wrote: ↑Fri Nov 11, 2022 3:56 pm
I have done something similar just recently
I used a Launch form and placed some filter objects on the left and the results are shown in an embedded iFrame. Did you think of something like this?
search_form.png
Hi Kev1n,
yes - that's nearly the solution. I will try to tell it my nubuilder

.l
Harald
Re: Search-form with lots of boolean fields
Posted: Mon Nov 14, 2022 12:21 pm
by hame
Hi all,
are there maybe already similar nubuilder projects in use or on the run ?
Thanks!
Harald
Re: Search-form with lots of boolean fields
Posted: Mon Nov 14, 2022 12:34 pm
by kev1n
Basically, you can check out the demo at
https://demo.nubuilder.cloud ( nuBuilder Objects -> Run iFrame (Form) )
Re: Search-form with lots of boolean fields
Posted: Mon Nov 14, 2022 5:20 pm
by kev1n
Let me know if you need more information
Re: Search-form with lots of boolean fields
Posted: Tue Nov 15, 2022 8:45 am
by miasoft
How to reset (cancel) the filter and return to the full list?
Re: Search-form with lots of boolean fields
Posted: Tue Nov 15, 2022 9:20 am
by kev1n
This is how I set up my search form:
1. All filter fields on my form have an attribute called "filter-field". This makes it easier to clear all as you will see in step 3.
filter_field.png
2. In the form's Custom Code:
Code: Select all
// Add an event listener for all filter fields and if the user pressed the "Enter" key, apply the search
$("[filter-field]").each(function() {
$(this).enterKey(function(e) {
applySearch();
});
});
function applySearch() {
var frame = $("#your_iframe_object_id")[0].contentWindow; // <--- Replace your_iframe_object_id with your iframe object id
// Set Hash Cookies (HK) for all filter fields:
// Example: Set HKs for Text fields
frame.nuSetProperty('filter_adr_last_name', adr_last_name.value);
frame.nuSetProperty('filter_adr_first_name', adr_first_name.value);
frame.nuSetProperty('filter_adr_company', adr_company.value);
// Set HKs for Boolean fields
frame.nuSetProperty('filter_adr_active', nuGetValue('adr_active') ? '1' : '');
frame.nuGetBreadcrumb();
}
3. Add a "Reset filter" button with an onclick event:
Code: Select all
$("[filter-field]").val(''); // empty all filter fields
applySearch();
4. iFrame Browse SQL:
5. iFrame BB (Before Browse) PHP Code:
Code: Select all
$filter = ' AND (1 = 1) ';
setFilter($filter, 'filter_adr_first_name', 'adr_first_name');
setFilter($filter, 'filter_adr_last_name', 'adr_last_name');
setFilter($filter, 'filter_adr_adr_company', 'adr_adr_company');
setFilter($filter, 'filter_adr_active', 'adr_active');
function setFilter(&$filter, $filterName, $columnName) {
$value = nuGetProperty($filterName);
if ($value != '') $filter .= " AND $columnName LIKE '%$value%' ";
}
$create = "CREATE TABLE #TABLE_ID# ";
$select = "
SELECT
address_id,
adr_first_name,
adr_last_name,
adr_company,
adr_active
FROM address
WHERE (1 = 1) -- your where clause, if there is any
" . $filter;
// To output the SQL to nuDebug Results:
// nuDebug($select);
nuRunQuery($create . $select);