How to use JSON to fill a text field?

Juan Manuel Clavero Almirón <[email protected]>
Newsgroups gmane.comp.otrs.devel
Message-ID <4E6C4135180B424CBFC6C6DE9456154A2106ACFC@SCPDPSEXMB01P.ssib.local>
Hi all,

We are still using OTRS 3.0. 
I want to fill TicketFreeText5 (a text field) with the phone number of the building selected in TicketFreeText6 (a select with all our possible locations).

In AgentTicketPhone.dtl, I’ve added (after dtl:block:TicketFreeText):
<!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
    $('#TicketFreeText6').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewPhoneTicket'), 'BuildingAJAXUpdate', 'TicketFreeText6', ['TicketFreeText5']);
    });
//]]></script>
<!--dtl:js_on_document_complete-->

In AgentTicketPhone.pm, I’ve added the Subaction 'BuildingAJAXUpdate'. It succesfully retrieves the phone number of the building, but fails when it has to response the AJAX call. I’ve tried two ways:

- First, I tried using Layout->JSONEncode:
    $JSONContent = $Self->{LayoutObject}->JSONEncode( 
        Data => {
            TicketFreeText5 => $BuildingData{Phone},
        }
    );

- Second, I tried using Layout->BuildSelectionJSON (it isn’t a select field, but I’ve seen it used in such cases [although can’t remember where]):
    $JSONContent = $Self->{LayoutObject}->BuildSelectionJSON(
        [
            {
                Name         => 'TicketFreeText5',
                Data         => $BuildingData{Phone},
                SelectedID   => $BuildingData{Phone},
            },
        ]
    );

Either way, the JSON string sent was {"TicketFreeText5":"3"}, being 3 the phone number. So I though everything was ok, but the web broser showed ‘TicketFreeText5’ instead of ‘3’ in the text field.

Anybody can help me to correctly fill a text field using AJAX?

Kind regards,
Juan Clavero

_______________________________________________
OTRS mailing list: dev - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.