custom search

68 views
Skip to first unread message

Andrea Fae'

unread,
Apr 25, 2019, 10:21:41 AM4/25/19
to web2py-users
I create a custom search, so not standard field with "Search" and "reset" button standard. How to click the button "Search" programmatically?
thank you

João Matos

unread,
Apr 25, 2019, 6:05:39 PM4/25/19
to web2py-users
You don't have the standard buttons, but have a search button created by you?

Andrea Fae'

unread,
Apr 26, 2019, 6:22:24 AM4/26/19
to web2py-users
They are the standard buttons "Search" and "Reset". I'd like from javascript in the html view to execute "Search" by code.
Thank you

Massimiliano

unread,
Apr 26, 2019, 6:31:16 AM4/26/19
to web...@googlegroups.com
Is difficult to understand how you intend to trigger the search without some infos.
Anyway just to give you an hint:

jQuery("#your_custom_widget").closest('form').trigger('submit');

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Massimiliano

andfae

unread,
Apr 26, 2019, 7:35:09 AM4/26/19
to web...@googlegroups.com
Hello I will give you the code....ok? 

<script>
    var srchI, srchF, srch;
    
    // funzione che consente di impostare la ricerca Dalla Data
    function datainizioSrch(){
        var dataDa = moment($('#datepickerI').datepicker("getDate")).format('YYYY-MM-DD');
        srchI ='evento.inizio >= ' + '"' + dataDa + '"';
        if (srchF != undefined) {
           srch = srchI + ' and ' + srchF;
        } else {
            srch = srchI;
        }
        // console.log(srch);
        $("#w2p_keywords").val(srch);
    }
    // funzione che consente di impostare la ricerca Alla Data
    function datafineSrch(){
        // aggiunge 1 giorno per includere anche l'ultimo giorno della data di ricerca dataA
        var dataA = moment($('#datepickerF').datepicker("getDate")).add(1, 'days').format('YYYY-MM-DD');
        srchF ='evento.fine <= ' + '"' + dataA + '"';
        if (srchI != undefined) {
           srch = srchI + ' and ' + srchF;
        } else {
            srch = srchF;
        }
        // console.log(srch);
        $("#w2p_keywords").val(srch);
    }

    $(document).ready(function(){

        // la funzione di ricerca standard della grid viene nascosta  
        $("#w2p_keywords").prop("type", "hidden");

        // Inserire gli elementi della ricerca custom dopo la ricerca standard ("#w2p_keywords").
        // Questo consente di non farla vedere sulle pagine edit e view
        // inserire i campi di ricerca nell'ordine inverso con i quali appaiono nella pagina
        var inputStr  = '<form class="form-inline"> <div class="form-group" style="padding-bottom:5px;">Dalla Data: <input type="text" id="datepickerI" class="datepicker" readonly="true" onchange="datainizioSrch()"></div> <div class="form-group" style="padding-bottom:5px;">Alla Data: <input type="text" id="datepickerF" class="datepicker" readonly="true" onchange="datafineSrch()"></div></form>';
        $(inputStr).insertAfter("#w2p_keywords");
        
        // definisco il datepicker
        $("#datepickerI").datepicker({
            dateFormat: "dd/mm/yy",
            autoSize: true,
            firstDay: 1,
            dayNamesMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"],
            monthNames: [ "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre" ],
        });
        $("#datepickerF").datepicker({
            dateFormat: "dd/mm/yy",
            autoSize: true,
            firstDay: 1,
            dayNamesMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"],
            monthNames: [ "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre" ],
        });
    });
</script>


To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Massimiliano

--
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/McFLFwcll88/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

villas

unread,
Apr 29, 2019, 12:43:00 PM4/29/19
to web2py-users
Hi Andfae
It seems you are using additional inputs to submit searches to a SQLFORM.grid search widget...

1. Do not wrap the new inputs inside a form, as you are adding them to an existing search form. 
2. Add something like this as the last line in your datainizioSrch function

$("#w2p_keywords").closest('form').find(':submit').click();

Best regards, D
To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Massimiliano

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/McFLFwcll88/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages