1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    1
    Vote Rating
    0
    Nick Rogers is on a distinguished road

      0  

    Default Answered: Search Form Restful submission

    Answered: Search Form Restful submission


    Hi,

    I have created a simple search form which is making a request to a RESTFUL api.

    I would like the RESTFUL request formatted from the fields in the form but do not know how to achieve this. I have two fields, q= the search term and type = the type of search I am creating. The result from the search will be in JSON format and get stored in a model/store.

    I have put the URL creation dynamically in the handler and this appears to be working although it is still adding query parameters of the fields to the end of the URL. It feels like a pretty hacky approach though. Also, I have another form with a lot of fields where this approach won't look so clever!

    Does anyone know a more 'elegant' EXTjs 4.1.3 solution for this?

    My code looks like this:
    Code:
            var navSearchForm = Ext.create('Ext.form.Panel', {
                xtype: 'form',
                ui: 'panel-transparent',
                url: '/UserSearch/',
                actionMethods: {
                    read: 'GET'
                },
                appendId: false,
                reader: {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'total'
                },
                flex: 1,
                layout: {
                    type: 'hbox',
                    align: 'middle',
                    pack: 'end'
                },
                items: [{
                    xtype: 'combo',
                    hideLabel: true,
                    displayField:   'name',
                    valueField:     'value',
                    typeAhead: true,
                    queryMode: 'local',
                    triggerAction: 'all',
                    name: 'type',
                    // value:          'phone',
                    emptyText: Cam.locale.header.nav.search.phoneNumber,
                    selectOnFocus: true,
                    width: 150,
                    store: Ext.create('Ext.data.Store', {
                        fields : ['name', 'value'],
                        data   : [
                            {name : 'Phone Number',   value: 'phone'},
                            {name : 'IMSI',  value: 'IMSI'}
                        ]
                    })
                },{
                    xtype: 'textfield',
                    name: 'q',
                    padding: 15,
                    fieldLabel: '',
                    emptyText: Cam.locale.header.nav.search.searchTerm,
                    allowBlank: false // requires a non-empty value
                }, {
                    xtype: 'button',
                    ui: 'btn-blue',
                    scale: '',
                    height: 30,
                    border: 0,
                    text: Cam.locale.header.nav.search.search,
                    handler: function() {
                        var form = this.up('form').getForm();
                        console.log(form);
                        existingURL = form.url;
                        if (form.isValid()) {
                            form.submit({
                                method: 'GET',
                                url: form.url + form._fields.items[0].value + '/' + form._fields.items[1].value,
                                success: function(form, action) {
                                   Ext.Msg.alert('Success', action.result.msg);
                                },
                                failure: function(form, action) {
                                    //Ext.Msg.alert('Failed', action.result.msg);
                                }
                            });
                        }
                    }
                }]
            });
    Many Thanks in advance

    Nick

  2. You say you are going to store the search in a store so why not use a proxy to load the search in the store's proxy's extraParams. So your form would do something like:

    Code:
    var values = form.getValues();
    
    store.proxy.extraParams = Ext.apply(store.proxy.extraParams || {}, {
        q    : values.q,
        type : values.type
    });
    
    store.load();

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Answers
    3462
    Vote Rating
    827
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You say you are going to store the search in a store so why not use a proxy to load the search in the store's proxy's extraParams. So your form would do something like:

    Code:
    var values = form.getValues();
    
    store.proxy.extraParams = Ext.apply(store.proxy.extraParams || {}, {
        q    : values.q,
        type : values.type
    });
    
    store.load();
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."