Ajaz - Populate form

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Ajaz - Populate form

Jussi Hirvi-2
I would like to populate a company-data form as soon as the user fills
in the Company ID field. How do I do this with jquery/Ajax?

I just realized that I have only used ajax to populate individual
fields. I would not like to make ten separate ajax files to fill in ten
form fields.

- Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Jolle Carlestam-3
The short answer is that you have your jquery/ajax call return a json object. From that you then populate each field with corresponding data from the json.

I can be more verbose if this doesn't help.

HDB
Jolle

2 sep 2011 kl. 11.34 skrev Jussi Hirvi:

> I would like to populate a company-data form as soon as the user fills in the Company ID field. How do I do this with jquery/Ajax?
>
> I just realized that I have only used ajax to populate individual fields. I would not like to make ten separate ajax files to fill in ten form fields.


#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Göran Törnquist-3
In reply to this post by Jussi Hirvi-2
How do you do it today? What is the response looking like when you fill
out your invidivual field today?

The solution to the problem is to get a JSON encoded response, from
which you can fill the fields in question.

/Göran

On 2011-09-02 11.34, Jussi Hirvi wrote:

> I would like to populate a company-data form as soon as the user fills
> in the Company ID field. How do I do this with jquery/Ajax?
>
> I just realized that I have only used ajax to populate individual
> fields. I would not like to make ten separate ajax files to fill in
> ten form fields.
>
> - Jussi
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to <[hidden email]>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Göran Törnquist-3
In reply to this post by Jolle Carlestam-3
You beat me to it with a mere minute :)

On 2011-09-02 11.59, Jolle Carlestam wrote:

> The short answer is that you have your jquery/ajax call return a json object. From that you then populate each field with corresponding data from the json.
>
> I can be more verbose if this doesn't help.
>
> HDB
> Jolle
>
> 2 sep 2011 kl. 11.34 skrev Jussi Hirvi:
>
>> I would like to populate a company-data form as soon as the user fills in the Company ID field. How do I do this with jquery/Ajax?
>>
>> I just realized that I have only used ajax to populate individual fields. I would not like to make ten separate ajax files to fill in ten form fields.
>
> #############################################################
> This message is sent to you because you are subscribed to
>    the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to:<[hidden email]>
> Send administrative queries to<[hidden email]>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Jussi Hirvi-2
In reply to this post by Göran Törnquist-3
On 2.9.2011 13.01, Göran Törnquist wrote:
> How do you do it today? What is the response looking like when you fill
> out your invidivual field today?

By response I suppose you mean the ajax file? Basically it captures
action_parameters, does rudimentary validation, then a search inline
returns a field value. My jquery line for calling this file is of this
type:

 
$('#select-myfield').load('local/ajax_myfield.lasso',{fname:'location_id',companyid:myvalue}
);

> The solution to the problem is to get a JSON encoded response, from
> which you can fill the fields in question.

Ok, I am googling on JSON object... I think I will get there soon enough.

- Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Göran Törnquist-3
Check out http://json.org/, the official site for JSON.

Then add something along these lines to return a json encoded response:

local(
     'myResponse' = map(
         'field1name' = 'field 1 data',
         'field2name' = 'field 2 data'
     )
);

encode_json(#myResponse);


Then in your Javascript, you have a object with the fields.

Remember to return your response with the mime type "text/json",
otherwise brilliant browsers like MSIE will trip here and there.

/Göran


On 2011-09-02 12.31, Jussi Hirvi wrote:

> On 2.9.2011 13.01, Göran Törnquist wrote:
>> How do you do it today? What is the response looking like when you fill
>> out your invidivual field today?
>
> By response I suppose you mean the ajax file? Basically it captures
> action_parameters, does rudimentary validation, then a search inline
> returns a field value. My jquery line for calling this file is of this
> type:
>
>
> $('#select-myfield').load('local/ajax_myfield.lasso',{fname:'location_id',companyid:myvalue}
> );
>
>> The solution to the problem is to get a JSON encoded response, from
>> which you can fill the fields in question.
>
> Ok, I am googling on JSON object... I think I will get there soon enough.
>
> - Jussi
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to <[hidden email]>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Jolle Carlestam-3
In reply to this post by Jussi Hirvi-2
2 sep 2011 kl. 12.31 skrev Jussi Hirvi:

> On 2.9.2011 13.01, Göran Törnquist wrote:
>> How do you do it today? What is the response looking like when you fill
>> out your invidivual field today?
>
> By response I suppose you mean the ajax file? Basically it captures action_parameters, does rudimentary validation, then a search inline returns a field value. My jquery line for calling this file is of this type:
>
> $('#select-myfield').load('local/ajax_myfield.lasso',{fname:'location_id',companyid:myvalue} );

Here's an example on the javascript part:

        $("#myselectfield").change(function(){
                if($(this).val()) {
                        $.getJSON("local/ajax.lasso", {fname:'location_id',companyid:myvalue}, function(json) {
                                if(!json.error) {
                                        $("#myfield1").val(json.field1)
                                        $("#myfield2").val(json.field2)
                                        $("#myhtml").html(json.html)
                                } else {
                                        alert(json.error)
                                }
                        });
                }
        });


And dummy Lasso code (for Lasso 9)
var(output = map)

// do magic to retrieve data here

if(error_code != 0) => {
        $output -> insert('error' = error_msg)
else
        $output -> insert('field1' = 'Some value')
        $output -> insert('field2' = 'Another value')
        $output -> insert('html' = '<strong>here I put HTML</strong>')

}

json_serialize($output)
content_type('application/json')

HTH

HDB
Jolle
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Jussi Hirvi-2
In reply to this post by Göran Törnquist-3
Thanks for tips...

On 2.9.2011 13.35, Göran Törnquist wrote:
> encode_json(#myResponse);

...especially this. I was going to format the JSON object manually.

> Remember to return your response with the mime type "text/json",
> otherwise brilliant browsers like MSIE will trip here and there.

... and this. May save me some headache later.

Something is not working, though. The mime type text/json stops it from
working.

When my ajax file contains only a test value:
        '{"name1":"value1"}';
and the jquery call is

           var myvar;
            $.ajax({
              url: 'ajax_companysearch.lasso',
              success: function(data) {
                  myvar = $.parseJSON( data );
                  alert(myvar.name1);
              }
            });

it works, and on page load I get the alert.
But if I add the content type line to the ajax file:
        content_type('text/json');
        '{"name1":"value1"}';
... then I cannot get an output. Instead I get an error "null is not an
object (evaluating myvar.name1)".

I tried adding datatype setting to the ajax call :

           var myvar;
            $.ajax({
              url: 'ajax_companysearch.lasso',
              datatype: 'json',
              success: function(data) {
                  myvar = $.parseJSON( data );
                  alert(myvar.name1);
              }
            });

...but it changes nothing. Any advice?

- Jussi




#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Göran Törnquist-3
That's because I gave you wrong info (obviously out of my head right now).

The content type is: application/json

/Göran

On 2011-09-02 13.11, Jussi Hirvi wrote:

> Thanks for tips...
>
> On 2.9.2011 13.35, Göran Törnquist wrote:
>> encode_json(#myResponse);
>
> ...especially this. I was going to format the JSON object manually.
>
>> Remember to return your response with the mime type "text/json",
>> otherwise brilliant browsers like MSIE will trip here and there.
>
> ... and this. May save me some headache later.
>
> Something is not working, though. The mime type text/json stops it
> from working.
>
> When my ajax file contains only a test value:
>     '{"name1":"value1"}';
> and the jquery call is
>
>        var myvar;
>         $.ajax({
>           url: 'ajax_companysearch.lasso',
>           success: function(data) {
>               myvar = $.parseJSON( data );
>               alert(myvar.name1);
>           }
>         });
>
> it works, and on page load I get the alert.
> But if I add the content type line to the ajax file:
>     content_type('text/json');
>     '{"name1":"value1"}';
> ... then I cannot get an output. Instead I get an error "null is not
> an object (evaluating myvar.name1)".
>
> I tried adding datatype setting to the ajax call :
>
>        var myvar;
>         $.ajax({
>           url: 'ajax_companysearch.lasso',
>           datatype: 'json',
>           success: function(data) {
>               myvar = $.parseJSON( data );
>               alert(myvar.name1);
>           }
>         });
>
> ...but it changes nothing. Any advice?
>
> - Jussi
>
>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to <[hidden email]>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Jolle Carlestam-3
In reply to this post by Jussi Hirvi-2
2 sep 2011 kl. 13.11 skrev Jussi Hirvi:

>    $.ajax({
>      url: 'ajax_companysearch.lasso',
>      datatype: 'json',
>      success: function(data) {
>          myvar = $.parseJSON( data );
>          alert(myvar.name1);
>      }
>    });
>
> ...but it changes nothing. Any advice?

The chosen construct is overly complicated. Use getJSON as I suggested instead.

HDB
Jolle
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Jussi Hirvi-2
In reply to this post by Göran Törnquist-3
On 2.9.2011 14.15, Göran Törnquist wrote:
> That's because I gave you wrong info (obviously out of my head right now).
>
> The content type is: application/json

Ok, thanks. I was _so_ close of finding this out myself.

It did not make my code work yet, though. I will next see into Jolle's
getJSON hint.

- Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Dave Bruhn
In reply to this post by Jussi Hirvi-2
You use Ajaz hands?

Sorry, I couldn't believe no one went there...
---
Dave Bruhn
Help Desk Analyst
North Carolina Hospital Association
PO Box 4449
Cary, NC 27519-4449
919-677-4145 (office)
[hidden email]
http://www.ncha.org

On Sep 2, 2011, at 5:34 AM, Jussi Hirvi wrote:

> I would like to populate a company-data form as soon as the user fills in the Company ID field. How do I do this with jquery/Ajax?
>
> I just realized that I have only used ajax to populate individual fields. I would not like to make ten separate ajax files to fill in ten form fields.
>
> - Jussi
> #############################################################
> This message is sent to you because you are subscribed to
> the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Jussi Hirvi-2
On 2.9.2011 15.45, Dave Bruhn wrote:
> You use Ajaz hands?
>
> Sorry, I couldn't believe no one went there...

Is that from some cleaning product commercial? I found a silly youtube
video where somebody puts Ajax (cleaning product) on his hands.

Seriously, ajaz was just a typo.

Meanwhile, I got the ajax thing with the JSON object running. I used
Jolle's code sample, and with that I had no more problem with mime types.

Tusen tack till Jolle och Göran.

- Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Dave Bruhn
I know it was a typo.  Just being silly on a Friday morning.
---
Dave Bruhn
Help Desk Analyst
North Carolina Hospital Association
PO Box 4449
Cary, NC 27519-4449
919-677-4145 (office)
[hidden email]
http://www.ncha.org

On Sep 2, 2011, at 9:10 AM, Jussi Hirvi wrote:

> On 2.9.2011 15.45, Dave Bruhn wrote:
>> You use Ajaz hands?
>>
>> Sorry, I couldn't believe no one went there...
>
> Is that from some cleaning product commercial? I found a silly youtube video where somebody puts Ajax (cleaning product) on his hands.
>
> Seriously, ajaz was just a typo.
>
> Meanwhile, I got the ajax thing with the JSON object running. I used Jolle's code sample, and with that I had no more problem with mime types.
>
> Tusen tack till Jolle och Göran.
>
> - Jussi
> #############################################################
> This message is sent to you because you are subscribed to
> the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Ajaz - Populate form

Jussi Hirvi-2
On 2.9.2011 16.16, Dave Bruhn wrote:
> I know it was a typo.  Just being silly on a Friday morning.

Here it is half past four PM already, and I will now forget about
c-o-d-i-n-g and go for a swim as long as it shines. Happy toiling! :-)

- Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>