1 (edited by boxygen 12/21/2017 10:33:46 am)

Topic: Auto Fill List of Values in a Text Input Fields

I am in a Fix. Trying to create a custom module and have added some more text based input fields in dimension_entry.php. When we enter any Value in Item Field (for e.g) the next time if entering the same item, then I have to type the whole value. Ideally the browser shall give me the list of previously feeded values in the same field. Just like it happens at other places of FA Forms like in customers.php any phone number once added is always made available by the browser to be selected in the same input filed.

Any special settings required for this? My clients are frustrated that they have to type in full the whole value again and again.

The code I have used for this is below

text_row(_("Item"). ":", 'item',null, 25, 75);

the screen shot of the page is here

Any guidance is highly appreciated.

Post's attachments

CustomDim.png 35.3 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.
www.boxygen.pk

Re: Auto Fill List of Values in a Text Input Fields

You may have to create / use a $_SESSION variable for it and / or enable autofill in the browser settings.

Re: Auto Fill List of Values in a Text Input Fields

I think autofill is already enable in browser settings that is why in Phone field the autofill values are shown and I don't think that in Customers Setup we have used $_SESSION variable for this input field.

Any suggestions

www.boxygen.pk

Re: Auto Fill List of Values in a Text Input Fields

It is possible that somewhere in your code prior to displaying the form field, you are doing something like this:

$_POST['item'] = '';

or

$_POST['item']  = $myrow["item"]; // which may be blank

Also, if the third parameter of the function text_row() is null, then the value of the field is automatically taken from the $_POST array as seen in the function text_input's second parameter which it becomes in includes/ui/ui_input.inc file.

Re: Auto Fill List of Values in a Text Input Fields

Try to add the flowing:

if (isset($_POST['update'])) {
    $Ajax->activate('_page_body');
}

assuming your update button name attribute is update

Phuong

Re: Auto Fill List of Values in a Text Input Fields

@apmuthu I have removed

$_POST['item']  = $myrow["item"];

and used

text_row(_("Item"). ":", 'item',@$myrow['item'], 25, 75);

@notrinos

I have applied

    $Ajax->activate('_page_body');

After add_dim() and update_dim() functions are called so that it applies to both Add or Update

But Unfortunately No Success

Below is the code of dimension_entry.php

<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
    Released under the terms of the GNU General Public License, GPL,
    as published by the Free Software Foundation, either version 3
    of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_DIMENSION';
$path_to_root = "../..";
include_once($path_to_root . "/includes/session.inc");

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");

include_once($path_to_root . "/admin/db/tags_db.inc");
include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
include_once($path_to_root . "/modules/clearing/includes/dim_db.inc");
include_once($path_to_root . "/modules/clearing/includes/dimensions_ui.inc");

$js = "";
if (user_use_date_picker())
    $js .= get_js_date_picker();
page(_($help_context = "Dimension Entry"), false, false, "", $js);

//---------------------------------------------------------------------------------------

if (isset($_GET['trans_no']))
{
    $selected_id = $_GET['trans_no'];
}
elseif(isset($_POST['selected_id']))
{
    $selected_id = $_POST['selected_id'];
}
else
    $selected_id = -1;
//---------------------------------------------------------------------------------------

if (isset($_GET['AddedID']))
{
    $id = $_GET['AddedID'];

    display_notification_centered(_("The dimension has been entered."));

    safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['UpdatedID']))
{
    $id = $_GET['UpdatedID'];

    display_notification_centered(_("The dimension has been updated."));
    safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['DeletedID']))
{
    $id = $_GET['DeletedID'];

    display_notification_centered(_("The dimension has been deleted."));
    safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['ClosedID']))
{
    $id = $_GET['ClosedID'];

    display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
    safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['ReopenedID']))
{
    $id = $_GET['ReopenedID'];

    display_notification_centered(_("The dimension has been re-opened. ") . " #$id");
    safe_exit();
}

//-------------------------------------------------------------------------------------------------

function safe_exit()
{
    global $path_to_root;

    hyperlink_no_params("", _("Enter a &new dimension"));
    echo "<br>";
    hyperlink_no_params($path_to_root . "/modules/clearing/inquiry/search_dimensions.php", _("&Select an existing dimension"));

    display_footer_exit();
}

//-------------------------------------------------------------------------------------

function can_process()
{
    global $selected_id, $Refs;

    if ($selected_id == -1)
    {
        if (!check_reference($_POST['ref'], ST_DIMENSION))
        {
            set_focus('ref');
            return false;
        }
    }

    if (strlen($_POST['name']) == 0)
    {
        display_error( _("The dimension name must be entered."));
        set_focus('name');
        return false;
    }

    if (!is_date($_POST['date_']))
    {
        display_error( _("The date entered is in an invalid format."));
        set_focus('date_');
        return false;
    }

    if (!is_date($_POST['due_date']))
    {
        display_error( _("The required by date entered is in an invalid format."));
        set_focus('due_date');
        return false;
    }

    return true;
}

//-------------------------------------------------------------------------------------

if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
{
    if (!isset($_POST['dimension_tags']))
        $_POST['dimension_tags'] = array();

    if (can_process())
    {

        if ($selected_id == -1)
        {
            $id = add_dim($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_'],
            $_POST['client'],
        $_POST['item'],
        $_POST['POL'],
        $_POST['mode'],
        $_POST['volume'],
        $_POST['weight'],
        $_POST['cont_no'],
        $_POST['equip_no'],
        $_POST['bl_no'],
        $_POST['bl_date'],
        $_POST['ETA'],
        $_POST['doc_copy'],
        $_POST['doc_org'],
        $_POST['gd_date'],
        $_POST['po_duty'],
        $_POST['po_do'],
        $_POST['po_wfg'],
        $_POST['destuff'],
        $_POST['assessment'],
        $_POST['delivery'],
        $_POST['gd_no'],
        $_POST['igm_no'],
        $_POST['igm_date'],
         $_POST['index_no'],
        $_POST['cash_no'],
        $_POST['cash_date'],
        $_POST['value'],
        $_POST['no_of_pkg'],
        $_POST['POD'],
        $_POST['gross_weight']);
            add_tag_associations($id, $_POST['dimension_tags']);
            meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
        }
        else
        {

            update_dim($selected_id, $_POST['Dref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_'],
            $_POST['client'],
         $_POST['item'],
         $_POST['POL'],
         $_POST['mode'],
         $_POST['volume'],
         $_POST['weight'],
         $_POST['cont_no'],
         $_POST['equip_no'],
         $_POST['bl_no'],
         $_POST['bl_date'],
         $_POST['ETA'],
         $_POST['doc_copy'],
         $_POST['doc_org'],
         $_POST['gd_date'],
         $_POST['po_duty'],
         $_POST['po_do'],
         $_POST['po_wfg'],
         $_POST['destuff'],
         $_POST['assessment'],
         $_POST['delivery'],
         $_POST['gd_no'],
         $_POST['igm_no'],
         $_POST['igm_date'],
         $_POST['index_no'],
         $_POST['cash_no'],
         $_POST['cash_date'],
         $_POST['value'],
         $_POST['no_of_pkg'],
         $_POST['POD'],
         $_POST['gross_weight']);
            update_tag_associations(TAG_DIMENSION, $selected_id, $_POST['dimension_tags']);

            meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
        }

        $Ajax->activate('_page_body');
    }

     }

//--------------------------------------------------------------------------------------

if (isset($_POST['delete']))
{

    $cancel_delete = false;

    // can't delete it there are productions or issues
    if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
    {
        display_error(_("This dimension cannot be deleted because it has already been processed."));
        set_focus('ref');
        $cancel_delete = true;
    }

    if ($cancel_delete == false)
    { //ie not cancelled the delete as a result of above tests

        // delete
        delete_dimension($selected_id);
        delete_tag_associations(TAG_DIMENSION,$selected_id, true);
        meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
    }
}

//-------------------------------------------------------------------------------------

if (isset($_POST['close']))
{

    // update the closed flag
    close_dimension($selected_id);
    meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
}

if (isset($_POST['reopen']))
{

    // update the closed flag
    reopen_dimension($selected_id);
    meta_forward($_SERVER['PHP_SELF'], "ReopenedID=$selected_id");
}
//-------------------------------------------------------------------------------------

start_form();

start_outer_table(TABLESTYLE2);

table_section(1);


if ($selected_id != -1)
{
    $myrow = get_dimension($selected_id);

    if (strlen($myrow[0]) == 0)
    {
        display_error(_("The dimension sent is not valid."));
        display_footer_exit();
    }

    // if it's a closed dimension can't edit it
    //if ($myrow["closed"] == 1)
    //{
    //    display_error(_("This dimension is closed and cannot be edited."));
    //    display_footer_exit();
    //}

    $_POST['ref'] = $myrow["reference"];
    $_POST['closed'] = $myrow["closed"];
    $_POST['name'] = $myrow["name"];
    $_POST['type_'] = $myrow["type_"];
    $_POST['date_'] = sql2date($myrow["date_"]);
    $_POST['due_date'] = sql2date($myrow["due_date"]);
    $_POST['memo_'] = get_comments_string(ST_DIMENSION, $selected_id);

    $tags_result = get_tags_associated_with_record(TAG_DIMENSION, $selected_id);
     $tagids = array();
     while ($tag = db_fetch($tags_result))
          $tagids[] = $tag['id'];
     $_POST['dimension_tags'] = $tagids;

    hidden('ref', $_POST['ref']);

    //label_row(_("Dimension Reference:"), $_POST['ref']); //Commented By Faisal

    ref_row(_("Dimension Reference:"), 'Dref', '', $_POST['ref']); //added by faisal

    hidden('selected_id', $selected_id);
}
else
{
    $_POST['dimension_tags'] = array();
    ref_row(_("Dimension Reference:"), 'ref', '', $Refs->get_next(ST_DIMENSION), false, ST_DIMENSION);
}

text_row_ex(_("Name") . ":", 'name', 25, 75);

$dim = get_company_pref('use_dimension');

number_list_row(_("Type"), 'type_', null, 1, $dim);

date_row(_("Start Date") . ":", 'date_');

date_row(_("Date Required By") . ":", 'due_date', '', null, $SysPrefs->default_dimension_required_by());

tag_list_row(_("Tags:"), 'dimension_tags', 5, TAG_DIMENSION, true);

textarea_row(_("Memo:"), 'memo_', null, 40, 5);


text_row(_("Client"). ":", 'client', @$myrow['client'], 25, 75);
text_row(_("Item"). ":", 'item',@$myrow['item'], 25, 75);
table_section(2);
text_row(_("POL"). ":", 'POL',@$myrow['POL'], 25, 75);
text_row(_("Mode"). ":", 'mode',@$myrow['mode'], 25, 75);
text_row(_("Volume"). ":", 'volume',@$myrow['volume'], 25, 75);
text_row(_("Weight"). ":", 'weight',@$myrow['weight'], 25, 75);
text_row(_("Container No"). ":", 'cont_no',@$myrow['cont_no'], 25, 75);


text_row(_("Equipment NO"). ":", 'equip_no',@$myrow['equip_no'], 25, 75);
text_row(_("BL No"). ":", 'bl_no',@$myrow['bl_no'], 25, 75);
text_row(_("BL Date"). ":", 'bl_date',@$myrow['bl_date'], 25, 75);
text_row(_("ETA"). ":", 'ETA',@$myrow['ETA'], 25, 75);
table_section(3);
text_row(_("Doc Copy"). ":", 'doc_copy',@$myrow['doc_copy'], 25, 75);
text_row(_("Doc Original"). ":", 'doc_org',@$myrow['doc_org'], 25, 75);
text_row(_("GD Date"). ":", 'gd_date',@$myrow['gd_date'], 25, 75);
text_row(_("Duty POrder"). ":", 'po_duty',@$myrow['po_duty'], 25, 75);

text_row(_("DO POrder"). ":", 'po_do',@$myrow['po_do'], 25, 75);
text_row(_("Wharfage POrder"). ":", 'po_wfg',@$myrow['po_wfg'], 25, 75);
text_row(_("Destuff Date"). ":", 'destuff',@$myrow['destuff'], 25, 75);
text_row(_("Assessment Date"). ":", 'assessment',@$myrow['assessment'], 25, 75);
text_row(_("Delivery Date"). ":", 'delivery',@$myrow['delivery'], 25, 75);
text_row(_("GD Number"). ":", 'gd_no',@$myrow['gd_no'], 25, 75);
table_section(4);
text_row(_("IGM Number"). ":", 'igm_no',@$myrow['igm_no'], 25, 75);
text_row(_("IGM Date"). ":", 'igm_date',@$myrow['igm_date'], 25, 75);
text_row(_("Index Number"). ":", 'index_no',@$myrow['index_no'], 25, 75);
text_row(_("Cash Number"). ":", 'cash_no',@$myrow['cash_no'], 25, 75);
text_row(_("Cash Date"). ":", 'cash_date',@$myrow['cash_date'], 25, 75);
text_row(_("Value"). ":", 'value',@$myrow['value'], 25, 75);
text_row(_("No Of Pkg"). ":", 'no_of_pkg',@$myrow['no_of_pkg'], 25, 75);
text_row(_("POD"). ":", 'POD',@$myrow['POD'], 25, 75);
text_row(_("Gross Weight"). ":", 'gross_weight',@$myrow['gross_weight'], 25, 75);

end_outer_table(1);

if (isset($_POST['closed']) && $_POST['closed'] == 1)
    display_note(_("This Dimension is closed."), 0, 0, "class='currentfg'");

if ($selected_id != -1)
{
    echo "<br>";
    submit_center_first('UPDATE_ITEM', _("Update"), _('Save changes to dimension'), 'default');
    if ($_POST['closed'] == 1)
        submit('reopen', _("Re-open This Dimension"), true, _('Mark this dimension as re-opened'), true);
    else
        submit('close', _("Close This Dimension"), true, _('Mark this dimension as closed'), true);
    submit_center_last('delete', _("Delete This Dimension"), _('Delete unused dimension'), true);
}
else
{
    submit_center('ADD_ITEM', _("Add"), true, '', 'default');
}
end_form();

//--------------------------------------------------------------------------------------------

end_page();

Your further help is highly needed.

www.boxygen.pk

Re: Auto Fill List of Values in a Text Input Fields

Try to move

$Ajax->activate('_page_body');

out of the can_process()
I guess if any statement in can_process() fails then $Ajax->activate('_page_body'); will not execute.

Phuong

Re: Auto Fill List of Values in a Text Input Fields

Yes. The Ajax should be out of the "if" construct.
Attached is the "beautified" page.

Post's attachments

dimension_entry.php1 11.9 kb, 11 downloads since 2017-12-22 

You don't have the permssions to download the attachments of this post.

9 (edited by boxygen 12/22/2017 10:17:19 am)

Re: Auto Fill List of Values in a Text Input Fields

Really the page is "Beautified"

Thanks @apmuthu and @notrinos

But unfortunately still not working sad

Can you please give a try. Maybe its my browser issue

Click to Login
id: admin
pass:Pakistan1947
company:Clearing

www.boxygen.pk

10 (edited by notrinos 12/22/2017 11:19:09 am)

Re: Auto Fill List of Values in a Text Input Fields

I see, because you redirect the page in add_dim() and update_dim() so the Ajax  will never be executed, in this case you have to call $Ajax->activate('_page_body'); before the if(can_process()).
This way just a workaroud for your problem

Phuong

Re: Auto Fill List of Values in a Text Input Fields

I really appreciate your feedback.

But unfortunately still it doesn't work after I applied @notrinos suggestion in post#10

Are you sure that

$Ajax->activate('_page_body');

controls this feature?

In order to dig further I took a complete fresh installation of FA243

In company_preferences.php I commented the line 126

//$Ajax->activate('_page_body');

But still this page is saving and showing Auto Fill Values.

In order to check further I took the core dimension_entry.php page and added

$Ajax->activate('_page_body');

Before

if (can_process())

Any value feeded in the Dimension Name is not appearing in the List of Values.

This exercise is saying that there may be some other code controlling this feature.

Any further feedback?

www.boxygen.pk

Re: Auto Fill List of Values in a Text Input Fields

Let's try these codes
I tested on my local machine and the input field suggesting all before values
https://prnt.sc/hr11p4

<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
    Released under the terms of the GNU General Public License, GPL,
    as published by the Free Software Foundation, either version 3
    of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_DIMENSION';
$path_to_root = "../../..";

include_once ($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/includes/date_functions.inc");
include_once ($path_to_root . "/includes/data_checks.inc");
include_once ($path_to_root . "/admin/db/tags_db.inc");
include_once ($path_to_root . "/dimensions/includes/dimensions_db.inc");
include_once ($path_to_root . "/modules/clearing/includes/dim_db.inc");
include_once ($path_to_root . "/modules/clearing/includes/dimensions_ui.inc");
include_once($path_to_root . "/includes/ui.inc");

$js = "";
if (user_use_date_picker())
    $js.= get_js_date_picker();
page(_($help_context = "Dimension Entry") , false, false, "", $js);
// ---------------------------------------------------------------------------------------
if (isset($_GET['trans_no']))
    $selected_id = $_GET['trans_no'];
elseif (isset($_POST['selected_id']))
    $selected_id = $_POST['selected_id'];
else $selected_id = - 1;
// ---------------------------------------------------------------------------------------
if (isset($_GET['AddedID'])) {
    $id = $_GET['AddedID'];
    display_notification_centered(_("The dimension has been entered."));
    safe_exit();
}
// ---------------------------------------------------------------------------------------
if (isset($_GET['UpdatedID'])) {
    $id = $_GET['UpdatedID'];
    display_notification_centered(_("The dimension has been updated."));
    safe_exit();
}
// ---------------------------------------------------------------------------------------
if (isset($_GET['DeletedID'])) {
    $id = $_GET['DeletedID'];
    display_notification_centered(_("The dimension has been deleted."));
    safe_exit();
}
// ---------------------------------------------------------------------------------------
if (isset($_GET['ClosedID'])) {
    $id = $_GET['ClosedID'];
    display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
    safe_exit();
}
// ---------------------------------------------------------------------------------------
if (isset($_GET['ReopenedID'])) {
    $id = $_GET['ReopenedID'];
    display_notification_centered(_("The dimension has been re-opened. ") . " #$id");
    safe_exit();
}
// -------------------------------------------------------------------------------------------------
function safe_exit() {
    global $path_to_root;
    hyperlink_no_params("", _("Enter a &new dimension"));
    echo "<br />";
    hyperlink_no_params($path_to_root . "/modules/clearing/inquiry/search_dimensions.php", _("&Select an existing dimension"));
    display_footer_exit();
}
// -------------------------------------------------------------------------------------
function can_process() {
    global $selected_id, $Refs;
    if ($selected_id == - 1) {
        if (!check_reference($_POST['ref'], ST_DIMENSION)) {
            set_focus('ref');
            return false;
        }
    }
    if (strlen($_POST['name']) == 0) {
        display_error(_("The dimension name must be entered."));
        set_focus('name');
        return false;
    }
    if (!is_date($_POST['date_'])) {
        display_error(_("The date entered is in an invalid format."));
        set_focus('date_');
        return false;
    }
    if (!is_date($_POST['due_date'])) {
        display_error(_("The required by date entered is in an invalid format."));
        set_focus('due_date');
        return false;
    }
    return true;
}
// -------------------------------------------------------------------------------------
if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
{
    if (!isset($_POST['dimension_tags'])) $_POST['dimension_tags'] = array();
    $Ajax->activate('_page_body');
    if (can_process())
    {
        if ($selected_id == - 1)
        {
            $id = add_dim($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_'], $_POST['client'], $_POST['item'], $_POST['POL'], $_POST['mode'], $_POST['volume'], $_POST['weight'], $_POST['cont_no'], $_POST['equip_no'], $_POST['bl_no'], $_POST['bl_date'], $_POST['ETA'], $_POST['doc_copy'], $_POST['doc_org'], $_POST['gd_date'], $_POST['po_duty'], $_POST['po_do'], $_POST['po_wfg'], $_POST['destuff'], $_POST['assessment'], $_POST['delivery'], $_POST['gd_no'], $_POST['igm_no'], $_POST['igm_date'], $_POST['index_no'], $_POST['cash_no'], $_POST['cash_date'], $_POST['value'], $_POST['no_of_pkg'], $_POST['POD'], $_POST['gross_weight']);
            add_tag_associations($id, $_POST['dimension_tags']);
            meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
        }
        else
        {
            update_dim($selected_id, $_POST['Dref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_'], $_POST['client'], $_POST['item'], $_POST['POL'], $_POST['mode'], $_POST['volume'], $_POST['weight'], $_POST['cont_no'], $_POST['equip_no'], $_POST['bl_no'], $_POST['bl_date'], $_POST['ETA'], $_POST['doc_copy'], $_POST['doc_org'], $_POST['gd_date'], $_POST['po_duty'], $_POST['po_do'], $_POST['po_wfg'], $_POST['destuff'], $_POST['assessment'], $_POST['delivery'], $_POST['gd_no'], $_POST['igm_no'], $_POST['igm_date'], $_POST['index_no'], $_POST['cash_no'], $_POST['cash_date'], $_POST['value'], $_POST['no_of_pkg'], $_POST['POD'], $_POST['gross_weight']);
            update_tag_associations(TAG_DIMENSION, $selected_id, $_POST['dimension_tags']);
            meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
        }
    }
}
// --------------------------------------------------------------------------------------
if (isset($_POST['delete'])) {
    $cancel_delete = false;
    // can't delete it there are productions or issues
    if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))     {
        display_error(_("This dimension cannot be deleted because it has already been processed."));
        set_focus('ref');
        $cancel_delete = true;
    }
    if ($cancel_delete == false)     { //ie not cancelled the delete as a result of above tests
        // delete
        delete_dimension($selected_id);
        delete_tag_associations(TAG_DIMENSION, $selected_id, true);
        meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
    }
}
// -------------------------------------------------------------------------------------
if (isset($_POST['close'])) {
    // update the closed flag
    close_dimension($selected_id);
    meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
}
if (isset($_POST['reopen'])) {
    // update the closed flag
    reopen_dimension($selected_id);
    meta_forward($_SERVER['PHP_SELF'], "ReopenedID=$selected_id");
}
// -------------------------------------------------------------------------------------
start_form();
start_outer_table(TABLESTYLE2);
table_section(1);
if ($selected_id != - 1) {
    $myrow = get_dimension($selected_id);
    if (strlen($myrow[0]) == 0)
    {
        display_error(_("The dimension sent is not valid."));
        display_footer_exit();
    }
    // if it's a closed dimension can't edit it
    // if ($myrow["closed"] == 1)
    // {
    //    display_error(_("This dimension is closed and cannot be edited."));
    //    display_footer_exit();
    // }
    $_POST['ref'] = $myrow["reference"];
    $_POST['closed'] = $myrow["closed"];
    $_POST['name'] = $myrow["name"];
    $_POST['type_'] = $myrow["type_"];
    $_POST['date_'] = sql2date($myrow["date_"]);
    $_POST['due_date'] = sql2date($myrow["due_date"]);
    $_POST['memo_'] = get_comments_string(ST_DIMENSION, $selected_id);
    $tags_result = get_tags_associated_with_record(TAG_DIMENSION, $selected_id);
    $tagids = array();
    while ($tag = db_fetch($tags_result)) $tagids[] = $tag['id'];
    $_POST['dimension_tags'] = $tagids;
    hidden('ref', $_POST['ref']);
    // label_row(_("Dimension Reference:"), $_POST['ref']); //Commented By Faisal
    ref_row(_("Dimension Reference:") , 'Dref', '', $_POST['ref']); //added by faisal
    hidden('selected_id', $selected_id);
} else {
    $_POST['dimension_tags'] = array();
    ref_row(_("Dimension Reference:") , 'ref', '', $Refs->get_next(ST_DIMENSION) , false, ST_DIMENSION);
}
text_row_ex(_("Name") . ":", 'name', 25, 75);
$dim = get_company_pref('use_dimension');
number_list_row(_("Type") , 'type_', null, 1, $dim);
date_row(_("Start Date") . ":", 'date_');
date_row(_("Date Required By") . ":", 'due_date', '', null, $SysPrefs->default_dimension_required_by());
tag_list_row(_("Tags:") , 'dimension_tags', 5, TAG_DIMENSION, true);
textarea_row(_("Memo:") , 'memo_', null, 40, 5);
text_row(_("Client") . ":", 'client', @$myrow['client'], 25, 75);
text_row(_("Item") . ":", 'item', @$myrow['item'], 25, 75);
table_section(2);
text_row(_("POL") . ":", 'POL', @$myrow['POL'], 25, 75);
text_row(_("Mode") . ":", 'mode', @$myrow['mode'], 25, 75);
text_row(_("Volume") . ":", 'volume', @$myrow['volume'], 25, 75);
text_row(_("Weight") . ":", 'weight', @$myrow['weight'], 25, 75);
text_row(_("Container No") . ":", 'cont_no', @$myrow['cont_no'], 25, 75);
text_row(_("Equipment NO") . ":", 'equip_no', @$myrow['equip_no'], 25, 75);
text_row(_("BL No") . ":", 'bl_no', @$myrow['bl_no'], 25, 75);
text_row(_("BL Date") . ":", 'bl_date', @$myrow['bl_date'], 25, 75);
text_row(_("ETA") . ":", 'ETA', @$myrow['ETA'], 25, 75);
table_section(3);
text_row(_("Doc Copy") . ":", 'doc_copy', @$myrow['doc_copy'], 25, 75);
text_row(_("Doc Original") . ":", 'doc_org', @$myrow['doc_org'], 25, 75);
text_row(_("GD Date") . ":", 'gd_date', @$myrow['gd_date'], 25, 75);
text_row(_("Duty POrder") . ":", 'po_duty', @$myrow['po_duty'], 25, 75);
text_row(_("DO POrder") . ":", 'po_do', @$myrow['po_do'], 25, 75);
text_row(_("Wharfage POrder") . ":", 'po_wfg', @$myrow['po_wfg'], 25, 75);
text_row(_("Destuff Date") . ":", 'destuff', @$myrow['destuff'], 25, 75);
text_row(_("Assessment Date") . ":", 'assessment', @$myrow['assessment'], 25, 75);
text_row(_("Delivery Date") . ":", 'delivery', @$myrow['delivery'], 25, 75);
text_row(_("GD Number") . ":", 'gd_no', @$myrow['gd_no'], 25, 75);
table_section(4);
text_row(_("IGM Number") . ":", 'igm_no', @$myrow['igm_no'], 25, 75);
text_row(_("IGM Date") . ":", 'igm_date', @$myrow['igm_date'], 25, 75);
text_row(_("Index Number") . ":", 'index_no', @$myrow['index_no'], 25, 75);
text_row(_("Cash Number") . ":", 'cash_no', @$myrow['cash_no'], 25, 75);
text_row(_("Cash Date") . ":", 'cash_date', @$myrow['cash_date'], 25, 75);
text_row(_("Value") . ":", 'value', @$myrow['value'], 25, 75);
text_row(_("No Of Pkg") . ":", 'no_of_pkg', @$myrow['no_of_pkg'], 25, 75);
text_row(_("POD") . ":", 'POD', @$myrow['POD'], 25, 75);
text_row(_("Gross Weight") . ":", 'gross_weight', @$myrow['gross_weight'], 25, 75);
end_outer_table(1);
if (isset($_POST['closed']) && $_POST['closed'] == 1)
    display_note(_("This Dimension is closed.") , 0, 0, "class='currentfg'");
if ($selected_id != - 1)
{
    echo "<br />";
    submit_center_first('UPDATE_ITEM', _("Update") , _('Save changes to dimension') , 'default');
    if ($_POST['closed'] == 1)
        submit('reopen', _("Re-open This Dimension") , true, _('Mark this dimension as re-opened') , true);
    else
        submit('close', _("Close This Dimension") , true, _('Mark this dimension as closed') , true);
    submit_center_last('delete', _("Delete This Dimension") , _('Delete unused dimension') , true);
} else {
    submit_center('ADD_ITEM', _("Add") , true, '', 'default');
}
end_form();
// --------------------------------------------------------------------------------------------
end_page();
Post's attachments

AjaxWorksInName.jpg 82.1 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.
Phuong

Re: Auto Fill List of Values in a Text Input Fields

Does the Ajax work for the Item field?

Re: Auto Fill List of Values in a Text Input Fields

Yes, also for items field I tested.

Phuong

Re: Auto Fill List of Values in a Text Input Fields

Then it should be a browser and version issue / OS issue.

Re: Auto Fill List of Values in a Text Input Fields

@notrinos you have added one line

include_once ($path_to_root . "/includes/ui.inc");

So finally the Core dimension_entry.php file looks like below after your modifications

<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
    Released under the terms of the GNU General Public License, GPL, 
    as published by the Free Software Foundation, either version 3 
    of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_DIMENSION';
$path_to_root = "..";
include_once($path_to_root . "/includes/session.inc");

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");

include_once($path_to_root . "/admin/db/tags_db.inc");
include_once($path_to_root . "/dimensions/includes/dimensions_db.inc");
include_once($path_to_root . "/dimensions/includes/dimensions_ui.inc");
include_once ($path_to_root . "/includes/ui.inc");


$js = "";
if (user_use_date_picker())
    $js .= get_js_date_picker();
page(_($help_context = "Dimension Entry"), false, false, "", $js);

//---------------------------------------------------------------------------------------

if (isset($_GET['trans_no']))
{
    $selected_id = $_GET['trans_no'];
} 
elseif(isset($_POST['selected_id']))
{
    $selected_id = $_POST['selected_id'];
}
else
    $selected_id = -1;
//---------------------------------------------------------------------------------------

if (isset($_GET['AddedID'])) 
{
    $id = $_GET['AddedID'];

    display_notification_centered(_("The dimension has been entered."));

    safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['UpdatedID'])) 
{
    $id = $_GET['UpdatedID'];

    display_notification_centered(_("The dimension has been updated."));
    safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['DeletedID'])) 
{
    $id = $_GET['DeletedID'];

    display_notification_centered(_("The dimension has been deleted."));
    safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['ClosedID'])) 
{
    $id = $_GET['ClosedID'];

    display_notification_centered(_("The dimension has been closed. There can be no more changes to it.") . " #$id");
    safe_exit();
}

//---------------------------------------------------------------------------------------

if (isset($_GET['ReopenedID'])) 
{
    $id = $_GET['ReopenedID'];

    display_notification_centered(_("The dimension has been re-opened. ") . " #$id");
    safe_exit();
}

//-------------------------------------------------------------------------------------------------

function safe_exit()
{
    global $path_to_root;

    hyperlink_no_params("", _("Enter a &new dimension"));
    echo "<br>";
    hyperlink_no_params($path_to_root . "/dimensions/inquiry/search_dimensions.php", _("&Select an existing dimension"));

    display_footer_exit();
}

//-------------------------------------------------------------------------------------

function can_process()
{
    global $selected_id, $Refs;

    if ($selected_id == -1) 
    {
        if (!check_reference($_POST['ref'], ST_DIMENSION))
        {
            set_focus('ref');
            return false;
        }
    }

    if (strlen($_POST['name']) == 0) 
    {
        display_error( _("The dimension name must be entered."));
        set_focus('name');
        return false;
    }

    if (!is_date($_POST['date_']))
    {
        display_error( _("The date entered is in an invalid format."));
        set_focus('date_');
        return false;
    }

    if (!is_date($_POST['due_date']))
    {
        display_error( _("The required by date entered is in an invalid format."));
        set_focus('due_date');
        return false;
    }

    return true;
}

//-------------------------------------------------------------------------------------

if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
{
    if (!isset($_POST['dimension_tags']))
        $_POST['dimension_tags'] = array();
        
    $Ajax->activate('_page_body');
    if (can_process()) 
    {

        if ($selected_id == -1) 
        {
            $id = add_dimension($_POST['ref'], $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
            add_tag_associations($id, $_POST['dimension_tags']);
            meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
        } 
        else 
        {

            update_dimension($selected_id, $_POST['name'], $_POST['type_'], $_POST['date_'], $_POST['due_date'], $_POST['memo_']);
            update_tag_associations(TAG_DIMENSION, $selected_id, $_POST['dimension_tags']);

            meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
        }
    }
}

//--------------------------------------------------------------------------------------

if (isset($_POST['delete'])) 
{

    $cancel_delete = false;

    // can't delete it there are productions or issues
    if (dimension_has_payments($selected_id) || dimension_has_deposits($selected_id))
    {
        display_error(_("This dimension cannot be deleted because it has already been processed."));
        set_focus('ref');
        $cancel_delete = true;
    }

    if ($cancel_delete == false) 
    { //ie not cancelled the delete as a result of above tests

        // delete
        delete_dimension($selected_id);
        delete_tag_associations(TAG_DIMENSION,$selected_id, true);
        meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
    }
}

//-------------------------------------------------------------------------------------

if (isset($_POST['close'])) 
{

    // update the closed flag
    close_dimension($selected_id);
    meta_forward($_SERVER['PHP_SELF'], "ClosedID=$selected_id");
}

if (isset($_POST['reopen'])) 
{

    // update the closed flag
    reopen_dimension($selected_id);
    meta_forward($_SERVER['PHP_SELF'], "ReopenedID=$selected_id");
}
//-------------------------------------------------------------------------------------

start_form();

start_table(TABLESTYLE2);

if ($selected_id != -1)
{
    $myrow = get_dimension($selected_id);

    if (strlen($myrow[0]) == 0) 
    {
        display_error(_("The dimension sent is not valid."));
        display_footer_exit();
    }

    // if it's a closed dimension can't edit it
    //if ($myrow["closed"] == 1) 
    //{
    //    display_error(_("This dimension is closed and cannot be edited."));
    //    display_footer_exit();
    //}

    $_POST['ref'] = $myrow["reference"];
    $_POST['closed'] = $myrow["closed"];
    $_POST['name'] = $myrow["name"];
    $_POST['type_'] = $myrow["type_"];
    $_POST['date_'] = sql2date($myrow["date_"]);
    $_POST['due_date'] = sql2date($myrow["due_date"]);
    $_POST['memo_'] = get_comments_string(ST_DIMENSION, $selected_id);
    
     $tags_result = get_tags_associated_with_record(TAG_DIMENSION, $selected_id);
     $tagids = array();
     while ($tag = db_fetch($tags_result)) 
          $tagids[] = $tag['id'];
     $_POST['dimension_tags'] = $tagids;    

    hidden('ref', $_POST['ref']);

    label_row(_("Dimension Reference:"), $_POST['ref']);

    hidden('selected_id', $selected_id);
} 
else 
{
    $_POST['dimension_tags'] = array();
    ref_row(_("Dimension Reference:"), 'ref', '', $Refs->get_next(ST_DIMENSION), false, ST_DIMENSION);
}

text_row_ex(_("Name") . ":", 'name', 50, 75);

$dim = get_company_pref('use_dimension');

number_list_row(_("Type"), 'type_', null, 1, $dim);

date_row(_("Start Date") . ":", 'date_');

date_row(_("Date Required By") . ":", 'due_date', '', null, $SysPrefs->default_dimension_required_by());

tag_list_row(_("Tags:"), 'dimension_tags', 5, TAG_DIMENSION, true);

textarea_row(_("Memo:"), 'memo_', null, 40, 5);

end_table(1);

if (isset($_POST['closed']) && $_POST['closed'] == 1)
    display_note(_("This Dimension is closed."), 0, 0, "class='currentfg'");

if ($selected_id != -1) 
{
    echo "<br>";
    submit_center_first('UPDATE_ITEM', _("Update"), _('Save changes to dimension'), 'default');
    if ($_POST['closed'] == 1)
        submit('reopen', _("Re-open This Dimension"), true, _('Mark this dimension as re-opened'), true);
    else    
        submit('close', _("Close This Dimension"), true, _('Mark this dimension as closed'), true);
    submit_center_last('delete', _("Delete This Dimension"), _('Delete unused dimension'), true);
}
else
{
    submit_center('ADD_ITEM', _("Add"), true, '', 'default');
}
end_form();

//--------------------------------------------------------------------------------------------

end_page();

Unfortunately I couldn't get results. I have applied all the changes to the latest version of FA at following URL

Click to Login
id: admin
pass:Pakistan1947
company:Clearing

www.boxygen.pk

Re: Auto Fill List of Values in a Text Input Fields

ah, the added line

include_once ($path_to_root . "/includes/ui.inc");

is not necessary, because I don't have other files in the clearing folder so the page needs include this to show its elements.

Your demo does not work as expected, Then it should be a browser and version issue / OS issue, as @apmuthu said

Post's attachments

dim_1_2.zip 5.5 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.
Phuong

Re: Auto Fill List of Values in a Text Input Fields

Thanks a lot, you have take such a pain for my problem.

You may be right, but how does the browser and version issue / OS issue is only affecting dimension_entry.php page while other pages like I mentioned earlier company_preferences.php is working fine on the same browser, version and OS?

www.boxygen.pk

19 (edited by notrinos 12/23/2017 05:21:51 am)

Re: Auto Fill List of Values in a Text Input Fields

I was not right @Boxygen, I have just tested again on original dimension entry and the name field did not suggest the earlier values.
The problem is not browser, version or OS.

I guess the meta_forward() function somehow cleared all the earlier values, you may need to dig into Ajax system to find out where it is.

You can check by comment out the meta_forward() statement and see the values stored for the next entry (remember to keep $Ajax->activate('_page_body') ).

Phuong

Re: Auto Fill List of Values in a Text Input Fields

I have no words to thank you @notrinos and @apmuthu.

You are right. After commenting meta_forward() it is working.

Can you guide how to debug Ajax? I am very poor in that smile

www.boxygen.pk

Re: Auto Fill List of Values in a Text Input Fields

Examples of meta_forward() usage are here where the get variables are overwritten.

Which of the 5 lines calling the meta_forward() constructs did you comment out?

Re: Auto Fill List of Values in a Text Input Fields

exit; statement in ui_controls.inc line 168 is the cause of @boxygen's trouble, I don't know why but you can temporarily  create your own meta_forward function without the exit; statement so that your module can work as it is now.
Something like this

function clearing_meta_forward($forward_to, $params="", $timeout=0)
{
    global $Ajax;
    echo "<meta http-equiv='Refresh' content='".$timeout."; url=$forward_to?$params'>\n";
    echo "<center><br>" . _("You should automatically be forwarded.");
    echo " " . _("If this does not happen") . " " . "<a href='$forward_to?$params'>" . _("click here") . "</a> " . _("to continue") . ".<br><br></center>\n";
    if ($params !='') $params = '?'.$params;
    $Ajax->redirect($forward_to.$params);
    //exit;
}
Phuong

Re: Auto Fill List of Values in a Text Input Fields

@notrinos: Why does it work everywhere else? What happens if the "exit;" is commented out in the main function itself?

@joe: was that some debug code that got left behind or do we need another argument for the function to conditionally execute an exit?

Re: Auto Fill List of Values in a Text Input Fields

I don't know. We must address this to @itronics.

It might have something to do with ajax.

/Joe

25 (edited by notrinos 12/24/2017 03:57:12 am)

Re: Auto Fill List of Values in a Text Input Fields

@apmuthu
The other places are working because they are not calling meta_forward after form submit, I guess anywhere calling meta_forward after submit form will not store the values fed for next entry.

About the exit; in the ui_controls.inc line 168 we can understand its use through an example like following:

Let's comment out exit; in ui_controls.inc line 168
Now we make an sales entry, says Sales Quotation Entry
After process the order the $_SESSION['Items'] will be cleared by the processing_end() at line 492 and function meta_forward will be called at line 501 of sales_order_entry.php, since the exit; is disabled so after redirect all statements in the sales_order_entry.php will not be stopped then we can see the errors:


Undefined index: Items in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 700
Trying to get property of non-object in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 700
Undefined index: Items in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 707
Trying to get property of non-object in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 707
Undefined index: Items in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 713
Trying to get property of non-object in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 713
Undefined index: Items in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 719
Trying to get property of non-object in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 719
Unhandled exception [0]: Call to a member function is_started() on null. in file: C:\xampp\htdocs\fa243\sales\sales_order_entry.php at line 737
exception_handler((Error Object))


In case of Dimension Entry the exit; can be disabled without any errors. So I think @apmuthu's suggestion for another argument for the function to conditionally execute an exit maybe good

Phuong