Results 1 to 8 of 8

Thread: Passing Values from Date Picker/Select Field to URL Query - How?

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Location
    Aveiro, Portugal
    Posts
    8
    Vote Rating
    0
      0  

    Default Unanswered: Passing Values from Date Picker/Select Field to URL Query - How?

    Hello!
    I'm using Sencha Touch 2 with Sencha Architect 2 to build a webapp to help Portuguese people check their train times. I have a webservice in which I send data from the form in the app. E get the app to send the departure and arrival values, but not the ones from the date picker and the select field. Something must be wrong in my code, but I can't seem to figure out what.

    So far, this is my code for the search view:
    Code:
    Ext.define('MyApp.view.Pesquisar', {
        extend: 'Ext.form.Panel',
        alias: 'widget.pesquisar',
    
    
        config: {
            id: 'pesquisar',
            method: 'get',
            standardSubmit: true,
            submitOnAction: true,
            url: '',
            items: [
                {
                    xtype: 'fieldset',
                    title: 'Estaes',
                    items: [
                        {
                            xtype: 'textfield',
                            id: 'departure',
                            itemId: 'departure',
                            label: 'Origem',
                            name: 'departure',
                            placeHolder: 'Estao'
                        },
                        {
                            xtype: 'textfield',
                            id: 'arrival',
                            itemId: 'arrival',
                            label: 'Destino',
                            name: 'arrival',
                            placeHolder: 'Estao'
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    title: 'Data e Hora',
                    items: [
                        {
                            xtype: 'datepickerfield',
                            id: 'day',
                            itemId: 'day',
                            label: 'Data',
                            name: 'data',
                            value: {
                                year: 2012,
                                month: 6,
                                day: 16
                            },
                            autoComplete: true,
                            placeHolder: 'aaaa-mm-dd',
                            dateFormat: 'Y-m-d',
                            picker: {
                                useTitles: true,
                                dayText: 'Dia',
                                monthText: 'Ms',
                                slotOrder: [
                                    'year',
                                    'month',
                                    'day'
                                ],
                                yearFrom: 2011,
                                yearText: 'Ano',
                                doneButton: 'Inserir',
                                cancelButton: 'Cancelar'
                            }
                        },
                        {
                            xtype: 'selectfield',
                            id: 'hour',
                            itemId: 'hour',
                            label: 'Hora',
                            name: 'hour',
                            placeHolder: 'Hora de Partida',
                            options: [
                                {
                                    text: 'Qualquer Hora',
                                    value: 'qq'
                                },
                                {
                                    text: '0h00',
                                    value: '0'
                                },
                                {
                                    text: '1h00',
                                    value: '1'
                                },
                                {
                                    text: '2h00',
                                    value: '2'
                                },
                                {
                                    text: '3h00',
                                    value: '3'
                                },
                                {
                                    text: '4h00',
                                    value: '4'
                                },
                                {
                                    text: '5h00',
                                    value: '5'
                                },
                                {
                                    text: '6h00',
                                    value: '6'
                                },
                                {
                                    text: '7h00',
                                    value: '7'
                                },
                                {
                                    text: '8h00',
                                    value: '8'
                                },
                                {
                                    text: '9h00',
                                    value: '9'
                                },
                                {
                                    text: '10h00',
                                    value: '10'
                                },
                                {
                                    text: '11h00',
                                    value: '11'
                                },
                                {
                                    text: '12h00',
                                    value: '12'
                                },
                                {
                                    text: '13h00',
                                    value: '13'
                                },
                                {
                                    text: '14h00',
                                    value: '14'
                                },
                                {
                                    text: '15h00',
                                    value: '15'
                                },
                                {
                                    text: '16h00',
                                    value: '16'
                                },
                                {
                                    text: '17h00',
                                    value: '17'
                                },
                                {
                                    text: '18h00',
                                    value: '18'
                                },
                                {
                                    text: '19h00',
                                    value: '19'
                                },
                                {
                                    text: '20h00',
                                    value: '20'
                                },
                                {
                                    text: '21h00',
                                    value: '21'
                                },
                                {
                                    text: '22h00',
                                    value: '22'
                                },
                                {
                                    text: '23h00',
                                    value: '23'
                                }
                            ]
                        }
                    ]
                },
                {
                    xtype: 'button',
                    handler: function(button, event) {
                        var form = Ext.getCmp('pesquisar');
                        form.submit({
                            url: 'http://poucaterra.joaodias.me/searchData/getData.php',
                            method: 'GET',
                            success: function (frm, res)  {
                                alert('Form submitted: ');
                            },
                            failure: function (frm, res) {
                                alert('Form no submit!');
                            }
                        });
                    },
                    itemId: 'submit',
                    text: 'Consultar'
                }
            ]
        }
    
    
    });
    If I perform a query now, I get the url "http://poucaterra.joaodias.me/searchData/getData.php?departure=cityA&arrival=cityB", which is not enough to perform a sucessfull query.

    I need to get "departure", "arrival, but also "day" and "hour".
    Is there something extra I need to setup for date selectors and select fields?

    Help, please

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,317
    Answers
    3882
    Vote Rating
    1291
      0  

    Default

    The reason is because of your use of standardSubmit. The <input> fields for the datepickerfield and selectfield are disabled so a standardSubmit form will not submit these values. Remove standardSubmit config and it will try to include them in.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Location
    Aveiro, Portugal
    Posts
    8
    Vote Rating
    0
      0  

    Default

    Hey, thanks, Mitchell You're the man!
    Now I'm getting "XMLHttpRequest cannot load http://poucaterra.joaodias.me/search...=1339956189118. Origin http://localhost is not allowed by Access-Control-Allow-Origin."

    How can I solve this?

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,317
    Answers
    3882
    Vote Rating
    1291
      0  

    Default

    enable-cors.org

    Your server needs to support CORS to do cross-origin requests
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  5. #5
    Sencha User
    Join Date
    Apr 2012
    Location
    Aveiro, Portugal
    Posts
    8
    Vote Rating
    0
      0  

    Default

    Ok, I think I've accomplished that, by putting an htaccess file with "".

    Now I get Uncaught Error: You're trying to decode an invalid JSON String: Error: Departure And Arrival Info Are Required

    It seems that now, without the StandardSubmit active, and CORS installed, my query doesn't send any query parameters. I get that "Error: Departure and Arrival Info Are Required" when i don't send any query parameters.

    I think I have it installed, because i get

    Code:
    HTTP/1.1 200 OK
    Date: Mon, 18 Jun 2012 12:47:04 GMT
    Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
    Vary: User-Agent,Accept-Encoding
    Access-Control-Allow-Origin: *
    Content-Type: text/html;charset=ISO-8859-1
    when i perform
    Code:
    curl -I poucaterra.joaodias.me/
    I'm sorry to bother with all theses questions, but I'm kinda noob with all this.

  6. #6
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,317
    Answers
    3882
    Vote Rating
    1291
      0  

    Default

    You need to response with somethign like

    Code:
    {
        "success" : true
    }
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

  7. #7
    Sencha User
    Join Date
    Apr 2012
    Location
    Aveiro, Portugal
    Posts
    8
    Vote Rating
    0
      0  

    Default

    what do you mean?

    Because I have that in my submit button...

    Code:
     {
                    xtype: 'button',
                    handler: function(button, event) {
                        var form = Ext.getCmp('pesquisar');
                        form.submit({
                            url: 'searchData/getData.php',
                            method: 'GET',
                            success: function (frm, res)  {
                                alert('Formulrio inserido com sucesso!');
                            },
                            failure: function (frm, res) {
                                alert('Erro.Formulrio inserido sem sucesso');
                            }
                        });
                    },
                    itemId: 'submit',
                    text: 'Consultar'
                }
    Is this it?
    Sorry, I'm all confused...

  8. #8
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,317
    Answers
    3882
    Vote Rating
    1291
      0  

    Default

    respond from the server
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •