dolibarr 21.0.0-alpha
ajax.lib.php File Reference

Page called to enhance interface with Javascript and Ajax features. More...

Go to the source code of this file.

Functions

 ajax_autocompleter ($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
 Generic function that return javascript to add to transform a common input text or select field into an autocomplete field by calling an Ajax page (ex: /societe/ajax/ajaxcompanies.php).
 
 ajax_multiautocompleter ($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
 Generic function that return javascript to add to a page to transform a common input text field into an autocomplete field by calling an Ajax page (ex: core/ajax/ziptown.php).
 
 ajax_dialog ($title, $message, $w=350, $h=150)
 Show an ajax dialog.
 
 ajax_combobox ($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
 Convert a html select field into an ajax combobox.
 
 ajax_event ($htmlname, $events)
 Add event management script.
 
 ajax_constantonoff ($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='', $morecss='inline-block', $userconst=0)
 On/off button for constant.
 
 ajax_object_onoff ($object, $code, $field, $text_on, $text_off, $input=array(), $morecss='', $htmlname='', $forcenojs=0, $moreparam='')
 On/off button to change a property status of an object This uses the ajax service objectonoff.php (May be called when MAIN_DIRECT_STATUS_UPDATE is set for some pages)
 

Detailed Description

Page called to enhance interface with Javascript and Ajax features.

Definition in file ajax.lib.php.

Function Documentation

◆ ajax_autocompleter()

ajax_autocompleter ( $selected,
$htmlname,
$url,
$urloption = '',
$minLength = 2,
$autoselect = 0,
$ajaxoptions = array(),
$moreparams = '' )

Generic function that return javascript to add to transform a common input text or select field into an autocomplete field by calling an Ajax page (ex: /societe/ajax/ajaxcompanies.php).

The HTML field must be an input text with id=search_$htmlname. This use the jQuery "autocomplete" function. If we want to use the select2, we must instead use input select into functions that call this method.

Parameters
string$selectedPreselected value
string$htmlnameHTML name of input field
string$urlAjax Url to call for request: /path/page.php. Must return a json array ('key'=>id, 'value'=>String shown into input field once selected, 'label'=>String shown into combo list)
string$urloptionMore parameters on URL request
int$minLengthMinimum number of chars to trigger that Ajax search
int$autoselectAutomatic selection if just one value (trigger("change") on field is done if search return only 1 result)
array<string,string|string[]>$ajaxoptions Multiple options array
  • Ex: array('update'=>array('field1','field2'...)) will reset field1 and field2 once select done
  • Ex: array('disabled'=> )
  • Ex: array('show'=> )
  • Ex: array('update_textarea'=> )
  • Ex: array('option_disabled'=> id to disable and warning to show if we select a disabled value (this is possible when using autocomplete ajax)
string$moreparamsMore params provided to ajax call
Returns
string Script

Definition at line 49 of file ajax.lib.php.

References getDolGlobalString().

Referenced by Form\select_company(), Form\select_contact(), Form\select_produits(), Form\select_produits_fournisseurs(), FormProjets\select_projects(), and FormCompany\selectCompaniesForNewContact().

◆ ajax_combobox()

ajax_combobox ( $htmlname,
$events = array(),
$minLengthToAutocomplete = 0,
$forcefocus = 0,
$widthTypeOfAutocomplete = 'resolve',
$idforemptyvalue = '-1',
$morecss = '' )

Convert a html select field into an ajax combobox.

Use ajax_combobox() only for small combo list! If not, use instead ajax_autocompleter(). TODO: It is used when COMPANY_USE_SEARCH_TO_SELECT and CONTACT_USE_SEARCH_TO_SELECT are set by html.formcompany.class.php. Should use ajax_autocompleter instead like done by html.form.class.php for select_produits.

Parameters
string$htmlnameName of html select field ('myid' or '.myclass')
array<array{method:string,url:string,htmlname:string,params?:array<string,string>}>$events More events option. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
int$minLengthToAutocompleteMinimum length of input string to start autocomplete
int$forcefocusForce focus on field
string$widthTypeOfAutocomplete'resolve' or 'off'
string$idforemptyvalue'-1'
string$morecssMore css
Returns
string Return html string to convert a select field into a combo, or '' if feature has been disabled for some reason.
See also
selectArrayAjax() of html.form.class

Definition at line 457 of file ajax.lib.php.

References ajax_event(), dol_escape_js(), and getDolGlobalString().

Referenced by Form\form_multicurrency_rate(), FormActions\form_select_status_action(), mailing_contacts1\formFilter(), mailing_fraise\formFilter(), mailing_partnership\formFilter(), mailing_pomme\formFilter(), mailing_thirdparties\formFilter(), mailing_thirdparties_services_expired\formFilter(), Form\getSelectConditionsPaiements(), Form\getSelectInvoiceSubtype(), BookKeeping\select_account(), FormAccounting\select_accounting_category(), Form\select_bom(), FormCompany\select_civility(), Form\select_comptes(), FormContract\select_contract(), Form\select_country(), Form\select_dolgroups(), Form\select_dolusers(), Form\select_incoterms(), FormCompany\select_juridicalstatus(), FormAdmin\select_language(), FormAdmin\select_menu(), FormAdmin\select_menu_families(), FormAdmin\select_paper_format(), Form\select_produits_fournisseurs_list(), Form\select_produits_list(), FormProjets\select_projects_list(), FormCompany\select_region(), Form\select_remises(), FormResource\select_resource_list(), FormCompany\select_state(), FormResource\select_state(), Form\select_thirdparty_list(), Form\select_type_of_lines(), FormSocialContrib\select_type_socialcontrib(), FormCron\select_typejob(), Form\select_types_paiements(), FormResource\select_types_resource(), FormEcm\selectAllSections(), Form\selectAvailabilityDelay(), FormBarCode\selectBarcodeType(), FormCompany\selectCompaniesForNewContact(), Form\selectcontacts(), FormWebsite\selectContainer(), Form\selectCurrency(), Form\selectExpenseCategories(), FormExpenseReport\selectExpensereportStatus(), FormTicket\selectGroupTickets(), Form\selectInputReason(), FormProjets\selectInvoiceAndLine(), Form\selectInvoiceRec(), FormProduct\selectLotStock(), Form\selectMassAction(), FormProduct\selectMeasuringUnits(), Form\selectModelMail(), Form\selectMultiCurrency(), FormProjets\selectOpportunityStatus(), Form\selectPriceBaseType(), FormProduct\selectProductNature(), FormPropal\selectProposalStatus(), FormCompany\selectProspectCustomerType(), FormCompany\selectProspectStatus(), FormWebsite\selectSampleOfContainer(), FormTicket\selectSeveritiesTickets(), Form\selectShippingMethod(), Holiday\selectStatutCP(), FormProjets\selectTasks(), Form\selectTransportMode(), FormCompany\selectTypeContact(), FormExpenseReport\selectTypeExpenseReport(), FormWebsite\selectTypeOfContainer(), FormAdmin\selectTypeOfFields(), Form\selectTypesIban(), FormTicket\selectTypesTickets(), FormProduct\selectWarehouses(), FormProduct\selectWorkstations(), Form\selectyesno(), FormFile\showdocuments(), CommonObject\showInputField(), and ExtraFields\showInputField().

◆ ajax_constantonoff()

ajax_constantonoff ( $code,
$input = array(),
$entity = null,
$revertonoff = 0,
$strict = 0,
$forcereload = 0,
$marginleftonlyshort = 2,
$forcenoajax = 0,
$setzeroinsteadofdel = 0,
$suffix = '',
$mode = '',
$morecss = 'inline-block',
$userconst = 0 )

On/off button for constant.

Parameters
string$codeName of constant
array$inputArray of complementary actions to do if success ("disabled"|"enabled'|'set'|'del') => CSS element to switch, 'alert' => message to show, ... Example: array('disabled'=>array(0=>'cssid')) @param int|null $entity Entity. Current entity is used if null. @param int $revertonoff 1=Revert on/off @param int $strict 0=Default, 1=Only the complementary actions "disabled and "enabled" (found into $input) are processed. Use only "disabled" with delConstant and "enabled" with setConstant.
int$forcereloadForce to reload page if we click/change value (this is supported only when there is no 'alert' option in input)
int$marginleftonlyshort1 = Add a short left margin on picto, 2 = Add a larger left margin on picto, 0 = No left margin.
int$forcenoajax1 = Force to use a ahref link instead of ajax code.
int$setzeroinsteadofdel1 = Set constant to '0' instead of deleting it when $input is empty.
string$suffixSuffix to use on the name of the switch picto when option is on. Example: '', '_red'
string$modeAdd parameter &mode= to the href link (Used for href link)
string$morecssMore CSS
int$userconst1=OnOff for user constant of user $userconst
Returns
string
See also
ajax_object_onoff() to update the status of an object

Definition at line 644 of file ajax.lib.php.

References dol_escape_js(), getDolGlobalString(), img_picto(), and newToken().

◆ ajax_dialog()

ajax_dialog ( $title,
$message,
$w = 350,
$h = 150 )

Show an ajax dialog.

Parameters
string$titleTitle of dialog box
string$messageMessage of dialog box
int$wWidth of dialog box
int$hheight of dialog box
Returns
string

Definition at line 414 of file ajax.lib.php.

References dol_string_nohtmltag(), and dol_textishtml().

◆ ajax_event()

ajax_event ( $htmlname,
$events )

Add event management script.

Parameters
string$htmlnameName of html select field ('myid' or '.myclass')
array$eventsAdd some Ajax events option on change of $htmlname component to call ajax to autofill a HTML element (select\htmlname and #inputautocompletehtmlname) Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
Returns
string Return JS string to manage event

Definition at line 560 of file ajax.lib.php.

Referenced by ajax_combobox(), Form\select_company(), and Form\select_contact().

◆ ajax_multiautocompleter()

ajax_multiautocompleter ( $htmlname,
$fields,
$url,
$option = '',
$minLength = 2,
$autoselect = 0 )

Generic function that return javascript to add to a page to transform a common input text field into an autocomplete field by calling an Ajax page (ex: core/ajax/ziptown.php).

The Ajax page can also returns several values (json format) to fill several input fields. The HTML field must be an input text with id=$htmlname. This use the jQuery "autocomplete" function.

Parameters
string$htmlnameHTML name of input field
string[]$fieldsArray of key of fields to autocomplete
string$urlURL for ajax request : /chemin/fichier.php
string$optionMore parameters on URL request
int$minLengthMinimum number of chars to trigger that Ajax search
int$autoselectAutomatic selection if just one value
Returns
string Script

Definition at line 306 of file ajax.lib.php.

Referenced by Form\select_incoterms(), FormCompany\select_ziptown(), and FormResource\select_ziptown().

◆ ajax_object_onoff()

ajax_object_onoff ( $object,
$code,
$field,
$text_on,
$text_off,
$input = array(),
$morecss = '',
$htmlname = '',
$forcenojs = 0,
$moreparam = '' )

On/off button to change a property status of an object This uses the ajax service objectonoff.php (May be called when MAIN_DIRECT_STATUS_UPDATE is set for some pages)

Parameters
Object$objectObject to set
string$codeName of property in object : 'status' or 'status_buy' for product by example
string$fieldName of database field : 'tosell' or 'tobuy' for product by example
string$text_onText if on ('Text' or 'Text:Picto on:Css picto on')
string$text_offText if off ('Text' or 'Text:Picto off:Css picto off')
array$inputArray of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid'))
string$morecssMore CSS
string$htmlnameName of HTML component. Keep '' or use a different value if you need to use this component several time on the same page for the same field.
int$forcenojsForce the component to work as link post (without javascript) instead of ajax call
string$moreparamWhen $forcenojs=1 then we can add more parameters to the backtopage URL. String must url encoded. Example: 'abc=def&fgh=ijk'
Returns
string html for button on/off
See also
ajax_constantonoff() to update that value of a constant

Definition at line 733 of file ajax.lib.php.

References $object.