From 947958c825d6b5dc721476a3ea7e64dd03bca0d8 Mon Sep 17 00:00:00 2001 From: BAKKBONE Australia <57392880+bakkbone@users.noreply.github.com> Date: Thu, 18 Jan 2024 21:41:17 +0800 Subject: [PATCH] 2.0.1 --- .../abn-lookup-for-gravity-forms-addon.php | 261 +++++++ .../abn-lookup-for-gravity-forms-fields.php | 667 ++++++++++++++++++ tags/2.0.1/abn-lookup-for-gravity-forms.php | 232 ++++++ tags/2.0.1/css/abnlookup-style.css | 41 ++ tags/2.0.1/css/abnlookup-style.min.css | 1 + tags/2.0.1/img/active.png | Bin 0 -> 7372 bytes tags/2.0.1/img/cancelled.png | Bin 0 -> 3316 bytes tags/2.0.1/img/error.png | Bin 0 -> 2222 bytes tags/2.0.1/img/loading.gif | Bin 0 -> 812 bytes tags/2.0.1/index.php | 2 + tags/2.0.1/js/abnlookup-script-admin.js | 403 +++++++++++ tags/2.0.1/js/abnlookup-script-admin.min.js | 1 + tags/2.0.1/js/abnlookup-script.js | 382 ++++++++++ tags/2.0.1/js/abnlookup-script.min.js | 1 + tags/2.0.1/readme.txt | 221 ++++++ trunk/abn-lookup-for-gravity-forms.php | 2 +- trunk/js/abnlookup-script.js | 16 +- trunk/js/abnlookup-script.min.js | 2 +- trunk/readme.txt | 4 +- 19 files changed, 2229 insertions(+), 7 deletions(-) create mode 100644 tags/2.0.1/abn-lookup-for-gravity-forms-addon.php create mode 100644 tags/2.0.1/abn-lookup-for-gravity-forms-fields.php create mode 100644 tags/2.0.1/abn-lookup-for-gravity-forms.php create mode 100644 tags/2.0.1/css/abnlookup-style.css create mode 100644 tags/2.0.1/css/abnlookup-style.min.css create mode 100644 tags/2.0.1/img/active.png create mode 100644 tags/2.0.1/img/cancelled.png create mode 100644 tags/2.0.1/img/error.png create mode 100644 tags/2.0.1/img/loading.gif create mode 100644 tags/2.0.1/index.php create mode 100644 tags/2.0.1/js/abnlookup-script-admin.js create mode 100644 tags/2.0.1/js/abnlookup-script-admin.min.js create mode 100644 tags/2.0.1/js/abnlookup-script.js create mode 100644 tags/2.0.1/js/abnlookup-script.min.js create mode 100644 tags/2.0.1/readme.txt diff --git a/tags/2.0.1/abn-lookup-for-gravity-forms-addon.php b/tags/2.0.1/abn-lookup-for-gravity-forms-addon.php new file mode 100644 index 0000000..1fdce6e --- /dev/null +++ b/tags/2.0.1/abn-lookup-for-gravity-forms-addon.php @@ -0,0 +1,261 @@ + __('Settings', 'abn-lookup-for-gravity-forms'), + "fields" => array( + array( + "label" => __('GUID', 'abn-lookup-for-gravity-forms'), + "name" => "guid", + "tooltip" => sprintf( __('To receive a GUID see %sweb services registration%s on the Australian Business Register website.', 'abn-lookup-for-gravity-forms'), '', '' ), + "type" => "guid" + ), + array( + "label" => __('Include CSS Styles', 'abn-lookup-for-gravity-forms'), + "type" => "checkbox", + "name" => "includecss", + "tooltip" => __('This option allows you to control whether to use the CSS styles provided in the plugin. If this is not enabled you will need to apply styles through your theme.', 'abn-lookup-for-gravity-forms'), + "choices" => array( + array( + "label" => __('Yes', 'abn-lookup-for-gravity-forms'), + "name" => "includecss", + "default_value" => true + ) + ) + ), + array( + "label" => __('Lookup timeout (seconds)', 'abn-lookup-for-gravity-forms'), + "type" => "text", + "name" => "lookup_timeout", + "tooltip" => __('This option controls the amount of time, in seconds, before a request to the ABR lookup system will timeout.', 'abn-lookup-for-gravity-forms'), + "default_value" => $abnlookup_options['lookup_timeout'] + ), + array( + "label" => __('Lookup Retries', 'abn-lookup-for-gravity-forms'), + "type" => "text", + "name" => "lookup_retries", + "tooltip" => __('This option controls the number of retries when a request to the ABR lookup system has failed. When all retries have been used the field will return the "Error communicating message" error message.', 'abn-lookup-for-gravity-forms'), + "default_value" => $abnlookup_options['lookup_retries'] + ) + ) + ), array( + "title" => __('Validation Messages', 'abn-lookup-for-gravity-forms'), + "fields" => array( + array( + "label" => __('ABN Not Valid', 'abn-lookup-for-gravity-forms'), + "name" => "validation_message_not_valid", + "tooltip" => __('This message is displayed to the user if they enter an ABN that is not valid.', 'abn-lookup-for-gravity-forms'), + "type" => "textarea", + "class" => "medium", + "default_value" => $abnlookup_options['validation_message_not_valid'] + ), + array( + "label" => __('ABN Not Active', 'abn-lookup-for-gravity-forms'), + "name" => "validation_message_activeabn", + "tooltip" => __('This message is displayed to the user if they enter an ABN that is not active.', 'abn-lookup-for-gravity-forms'), + "type" => "textarea", + "class" => "medium", + "default_value" => $abnlookup_options['validation_message_activeabn'] + ), + array( + "label" => __('ABN Not Registered for GST', 'abn-lookup-for-gravity-forms'), + "name" => "validation_message_reggst", + "tooltip" => __('This message is displayed to the user if they enter a ABN that is not registered for GST and the field validation is set to only allow ABNs that are GST registered.', 'abn-lookup-for-gravity-forms'), + "type" => "textarea", + "class" => "medium", + "default_value" => $abnlookup_options['validation_message_reggst'] + ), + array( + "label" => __('ABN Registered for GST', 'abn-lookup-for-gravity-forms'), + "name" => "validation_message_notreggst", + "tooltip" => __('This message is displayed to the user if they enter a ABN is registered for GST and the field validation is set to only allow ABNs that are not registered for GST.', 'abn-lookup-for-gravity-forms'), + "type" => "textarea", + "class" => "medium", + "default_value" => $abnlookup_options['validation_message_notreggst'] + ), + array( + "label" => __('ABN Not Correct Length', 'abn-lookup-for-gravity-forms'), + "name" => "validation_message_11_char", + "tooltip" => __('This message is displayed to the user if they enter a value into the ABN field that does not contain the required 11 characters that make up an ABN.', 'abn-lookup-for-gravity-forms'), + "type" => "textarea", + "class" => "medium", + "default_value" => $abnlookup_options['validation_message_11_char'] + ), + array( + "label" => __('Loading Message', 'abn-lookup-for-gravity-forms'), + "name" => "validation_message_loading", + "tooltip" => __('This message is displayed to the user when the ABN Lookup is running.', 'abn-lookup-for-gravity-forms'), + "type" => "textarea", + "class" => "medium", + "default_value" => $abnlookup_options['validation_message_loading'] + ), + array( + "label" => __('Error Communicating Message', 'abn-lookup-for-gravity-forms'), + "name" => "validation_message_error_communicating", + "tooltip" => __('This message is displayed to the user when the ABN Lookup script has failed to communicate with the Australian Business Register more than three times.', 'abn-lookup-for-gravity-forms'), + "type" => "textarea", + "class" => "medium", + "default_value" => $abnlookup_options['validation_message_error_communicating'] + ) + ) + ) + ); + } + + public function settings_guid(){ + $this->settings_text( + array( + "name" => "guid", + "class" => "large" + ) + ); + printf( + '
%s
%s
%s
%s
%s
%s
E834etYYMU!R(k%I>y{0IB(tYC E`?1R?HBJHplznvx3$9qjmzV%7XWHr$$x+iBsqC*LVFTk)dE-CR?DE# zYQ^G!Bz~V!X37+DK-oCe5XexPzL2W;nm00(HOxt%09*G(5hi=l6bfKyg mtjJXqFmTKc%H}+AR-|2K@)sCl^JQJsys;b4r-c4p;&Gc3I9{o)f8Nl(}+* zj0(G!NfPIJp!db&vFh-@OX1e##pKNUI{j>(#BH@n6HpEC#XZp_5*A$*vn(N9m|IwK z Lnl87JY(`6o-PccJ3FziyMZ6$pt`A`#X^>~&dki+kv8<=~C$ znCHw*-kiH8L=_WVgiav=238P{PN~OIjj}?3wue-vteb+wyPgHIt`LlM^xril)RLnE z^2`@r?VEkyLp3TgsEO#2D-cki2+v)b8khUl)}T)FJW(eeF2IPj(9)o)1CE{Vvu>l) zR$Cx>5aYZZ6hhl;R avwm`$oh>(<<8E!fsUqswOcyMT<3B9q3@dq1-kzS(|y zdFQ_7u}xHjZk%-GWaR$5bC$p%wwH|kY@e_ p!2O-!SewuTqR=q-mxPr7cUCCo kZR DPhk_H$5W@mS%S> zIcjLvN>7lztnu_+_5S;v4|`rr2VnELUyHmy5|*}!yGRzGR_fsyfB hC12`4E}x1 _p3cB z;z0D8!7mM$5eHf8a?+YDOEI^m5mH`frJgb=#fPZ}>DmRzzu%M~b;>K3rK?elsxm(> zI(@$nSyv>`mB?x1DU1|`AM?y%Hf#R=bsGtlquVrWi^(&b<=xq6zvbWE*I!HkFLQ2Y zUmC$pcGWuMeFR_mI`vvVCsOX#I8}aD6`>f;BJ~RaBhTK6P7!DTgnmm=+_wL^H#E*! zs7|()tSi4vrHb3)Uh#}mc4sb|!XSC05tE)6vppc!qLY5u%lzMB5^1xi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~U8t|ex^!HvuNTKP&ZXEEg~a9Db$QPBiI3&w%Ys1`nPm5yOn={V z1NTx>eZx69m?|xWzp@fbasxFrSPRiAV^Vzcd?$tEtc7~i)Cg}f$Rd;MuC%n7Jr&<$ zwK}_XI=sls!wesv%1SI(RUvTU0#>T4v3l{MI0o316cfikBPln)W2hG&(W)xJB9m;^ zaNlaRhuuK8R{QHilL;e*g_tcX!(wG60_V;lz$VV0$BLwYEUtwkY2Qky553Qw6D%^x zW(~bs?ayI1a4#igXvpEfIG=wuaOMn_&Ys0GA0>+CjP0hgXM@@$XIakU9hQ8_B9m;^ z(3z4l7 BPMCcY29fyBfQ z+&o!S1mEe?n3tf7B_&v(7&~ uJs$Ywqpa=o-PVeOb9&KJc%M2YSY(pT8hA0oZy-K? z X%OCxZug;j5>z!&f26Z~T mqg3wSzg0MHA3BtH zQ>6;@YBU&3OT)ADbiCB-@k+19NJfUxs8sxjT(nLXRA?+ceKY@+UN1c8MNfLSsZ@b> zmFnoe79ZL~`=LW~UEh9-f#hTiYqfaJcY}{sdOBXSIGrvispw5fapo|Wd!Flb!h>G) zY>$rik)imMgO5{NR8-I1*jV%*J&H%k$#}{;A~&Pe;+0m57djnYNfPH;typ6YbGheH za _ z;~I0A%RL>3597D!=;ijPsQvl033ouD_@XT$;va31ku$eqVsI}m4!vqM?#IXDVSGFu zXf#4RXN+siVQyPw K5;LB=|0ssI207*qoM6N<$g1$RYdH?_b literal 0 HcmV?d00001 diff --git a/tags/2.0.1/img/loading.gif b/tags/2.0.1/img/loading.gif new file mode 100644 index 0000000000000000000000000000000000000000..1c97cb570542080f601b49c441a65cb0272fca7c GIT binary patch literal 812 zcmZ?wbhEHb6k-r!*v!KqFE8)l;BfEWy@rN{0|ySo$H&i~KR+%mZr;3kOO`Czzkh#y zef|Ic{~2IF@jthpYe=xOV}PrXo&hr>P+ajR3nv!?4}%U!4aisq7Pko}Jy)+~xHI?j zJjVkix5V3$Gw023-FCTfOOwFq&!N|a=0#gazh5pKB*xwCROqOrd3x#5nJx+vfzP&N z?e&VjtDTc1J6lo^o6)XdqZL6$yB;i&Vu(q!nD#7k>7y&V@_lArGpO0Q@3ZiIevONQ zx@^s^3OiILi>L|zOcCJV$()?EH)*+z{ |vibm_E))0a80ne72KI~ioQ=b@6Q zKoqmZ9BX_8(9C9PWM$alvRFjxYSC1`EurhorJv0_pApA`&2WgrkAVzlIaqSb0LAcW z3N=1~sD@Wga$xY9=(Ui6;jq=;l+Cx-efOT*aQX^XheKkr1!Q*9fs$E?C}!U`=c(NK ze(%YC@hJ@23=K;Iz`=d_QwSRqG`KDGx1HEAsTog9IsuK|HrGwy{*&Hh&xK2@mWnb= zX)`?eDeStCT|6X_FfpD^D1ass9T8|E@xHs-J4v=59FweQ$qyVLdo5mbHi#a&S}MX3 zwb*>7;;L!7qAXI5KA(GTZkuvh{N7piJG`2$O-B=8j^<;7I$BD<%y{Rd^F164)&T!B BHO~M5 literal 0 HcmV?d00001 diff --git a/tags/2.0.1/index.php b/tags/2.0.1/index.php new file mode 100644 index 0000000..12c197f --- /dev/null +++ b/tags/2.0.1/index.php @@ -0,0 +1,2 @@ +' + value + ''); + } + } + + // now get their values + var enable_abnlookup_value = (typeof field['enable_abnlookup'] != 'undefined' && field['enable_abnlookup'] != '') ? field['enable_abnlookup'] : false; + var abnlookup_field_entity_value = (typeof field['abnlookup_results_enable'] != 'undefined' && field['abnlookup_results_enable'] != '') ? field['abnlookup_results_enable'] : false; + + // now set the value to the option field + if (enable_abnlookup_value != false) { + abnlookup_field.find("input:checkbox").prop('checked', true); + } else { + abnlookup_field.find("input:checkbox").prop('checked', false); + } + + if (abnlookup_field_entity_value != false) { + abnlookup_field_entity_results.find("input:checkbox").prop('checked', true); + } else { + abnlookup_field_entity_results.find("input:checkbox").prop('checked', false); + } + + if (field["abnlookup_results"] !== undefined) { + abnlookup_field_entity_results_setting.find("input#" + field["abnlookup_results"]).prop('checked', true); + } + + abnlookup_field_validate.find("select").val(field["field_validate_abnlookup"] == undefined ? "validabn" : field["field_validate_abnlookup"]); + abnlookup_field_link.find("select").val(field['field_link_abnlookup'] == undefined ? "" : field['field_link_abnlookup']); + + } + } else { + if ('text' == field_type) { + + // the fields + var abnlookup_field = jQuery(".abnlookup_field_setting"); + var abnlookup_field_validate = jQuery(".abnlookup_validate_field_setting"); + var abnlookup_field_link = jQuery(this).find(".abnlookup_link_field_setting"); + var abnlookup_field_entity_results = jQuery(".abnlookup_entity_results_setting"); + var abnlookup_field_entity_results_setting = jQuery(".abnlookup_entity_results_field_setting_text"); + + // lets display the options in the page + abnlookup_field.show(); + abnlookup_field_entity_results.show(); + if ( 'true'== field.enable_abnlookup ) { + // we do need to see the ABN Lookup field settings + abnlookup_field_validate.show(); + // we dont need to see the ABN Lookup results settings + abnlookup_field_link.hide(); + abnlookup_field_entity_results.hide(); + abnlookup_field_entity_results_setting.hide(); + } else { + abnlookup_field_validate.hide(); + abnlookup_field_link.hide(); + abnlookup_field_entity_results_setting.hide(); + } + + if ( 'true'== field.abnlookup_results_enable ) { + // we dont need to see the ABN Lookup field settings + abnlookup_field_validate.hide(); + + // we do need to see the ABN Lookup results settings + abnlookup_field_entity_results.show(); + abnlookup_field_entity_results_setting.show(); + abnlookup_field_link.show(); + } else { + abnlookup_field_link.hide(); + abnlookup_field_entity_results_setting.hide(); + } + + // first remove existing list of options + abnlookup_field_link.find('select option').remove(); + + // now to create the list of options and assign to link field + for (var i = 0; i < form.fields.length; i++) { + if ('true' == form.fields[i].enable_abnlookup) { + var value = form.fields[i].label; + var key = form.fields[i].id; + abnlookup_field_link.find('select').append(''); + } + } + + // now get their values + var enable_abnlookup_value = (typeof field['enable_abnlookup'] != 'undefined' && field['enable_abnlookup'] != '') ? field['enable_abnlookup'] : false; + var abnlookup_field_entity_value = (typeof field['abnlookup_results_enable'] != 'undefined' && field['abnlookup_results_enable'] != '') ? field['abnlookup_results_enable'] : false; + + // now set the value to the option field + if (enable_abnlookup_value != false) { + abnlookup_field.find("input:checkbox").prop('checked', true); + } else { + abnlookup_field.find("input:checkbox").prop('checked', false); + } + + if (abnlookup_field_entity_value != false) { + abnlookup_field_entity_results.find("input:checkbox").prop('checked', true); + } else { + abnlookup_field_entity_results.find("input:checkbox").prop('checked', false); + } + + if (field["abnlookup_results"] !== undefined) { + abnlookup_field_entity_results_setting.find("input#" + field["abnlookup_results"]).prop('checked', true); + } + + abnlookup_field_validate.find("select").val(field["field_validate_abnlookup"] == undefined ? "validabn" : field["field_validate_abnlookup"]); + abnlookup_field_link.find("select").val(field['field_link_abnlookup'] == undefined ? "" : field['field_link_abnlookup']); + + } else if ('select' == field_type) { + var abnlookup_field_business_name = jQuery(this).find(".abnlookup_business_name_field_setting"); + var abnlookup_field_link = jQuery(this).find(".abnlookup_link_field_setting"); + + // lets display the options in the page + abnlookup_field_business_name.show(); + if ( 'true'== field.abnlookup_enable_business_name ) { + abnlookup_field_link.show(); + } else { + abnlookup_field_link.hide(); + } + + + // now get their values + var abnlookup_field_business_name_value = (typeof field['abnlookup_enable_business_name'] != 'undefined' && field['abnlookup_enable_business_name'] != '') ? field['abnlookup_enable_business_name'] : false; + + // LINK FIELD - first delete existing list of options + abnlookup_field_link.find('select option').remove(); + + // now to create the list of options and assign to link field + for (var i = 0; i < form.fields.length; i++) { + if ('true' == form.fields[i].enable_abnlookup) { + var value = form.fields[i].label; + var key = form.fields[i].id; + abnlookup_field_link.find('select').append(''); + } + } + + // now set the value to the option field + if (abnlookup_field_business_name_value != false) { + abnlookup_field_business_name.find("input:checkbox").prop('checked', true); + } else { + abnlookup_field_business_name.find("input:checkbox").prop('checked', false); + } + + abnlookup_field_link.find("select").val(field['field_link_abnlookup'] == undefined ? "" : field['field_link_abnlookup']); + } else if ('radio' == field_type) { + var abnlookup_field_gst = jQuery(this).find(".abnlookup_gst_field_setting"); + var abnlookup_field_link = jQuery(this).find(".abnlookup_link_field_setting"); + + // lets display the options in the page + abnlookup_field_gst.show(); + if ( 'true'== field.abnlookup_enable_gst ) { + abnlookup_field_link.show(); + } else { + abnlookup_field_link.hide(); + } + + + // now get their values + var abnlookup_field_gst_value = (typeof field['abnlookup_enable_gst'] != 'undefined' && field['abnlookup_enable_gst'] != '') ? field['abnlookup_enable_gst'] : false; + + // LINK FIELD - first delete existing list of options + abnlookup_field_link.find('select option').remove(); + + // now to create the list of options and assign to link field + for (var i = 0; i < form.fields.length; i++) { + if ('true' == form.fields[i].enable_abnlookup) { + var value = form.fields[i].label; + var key = form.fields[i].id; + abnlookup_field_link.find('select').append(''); + } + } + + // now set the value to the option field + if (abnlookup_field_gst_value != false) { + abnlookup_field_gst.find("input:checkbox").prop('checked', true); + } else { + abnlookup_field_gst.find("input:checkbox").prop('checked', false); + } + + abnlookup_field_link.find("select").val(field['field_link_abnlookup'] == undefined ? "" : field['field_link_abnlookup']); + } else if ('date' == field_type) { + + // the fields + var abnlookup_field_entity_results = jQuery(".abnlookup_entity_results_setting"); + var abnlookup_field_link = jQuery(".abnlookup_link_field_setting"); + var abnlookup_field_entity_results_setting = jQuery(".abnlookup_entity_results_field_setting_date"); + //var abnlookup_field_validate = jQuery(".abnlookup_validate_field_setting"); + + // lets display the options in the page + abnlookup_field_entity_results.show(); + if ( 'true'== field.abnlookup_results_enable ) { + abnlookup_field_link.show(); + abnlookup_field_entity_results_setting.show(); + // abnlookup_field_validate.show(); + } else { + abnlookup_field_link.hide(); + abnlookup_field_entity_results_setting.hide(); + // abnlookup_field_validate.hide(); + } + + // first remove existing list of options + abnlookup_field_link.find('select option').remove(); + + // now to create the list of options and assign to link field + for (var i = 0; i < form.fields.length; i++) { + if ('true' == form.fields[i].enable_abnlookup) { + var value = form.fields[i].label; + var key = form.fields[i].id; + abnlookup_field_link.find('select').append(''); + } + } + + // now get their values + var abnlookup_field_entity_value = (typeof field['abnlookup_results_enable'] != 'undefined' && field['abnlookup_results_enable'] != '') ? field['abnlookup_results_enable'] : false; + + if (abnlookup_field_entity_value != false) { + abnlookup_field_entity_results.find("input:checkbox").prop('checked', true); + } else { + abnlookup_field_entity_results.find("input:checkbox").prop('checked', false); + } + + if (field["abnlookup_results"] !== undefined) { + abnlookup_field_entity_results_setting.find("input#" + field["abnlookup_results"]).prop('checked', true); + } + + //abnlookup_field_validate.find("select").val(field["field_validate_abnlookup"] == undefined ? "validabn" : field["field_validate_abnlookup"]); + abnlookup_field_link.find("select").val(field['field_link_abnlookup'] == undefined ? "" : field['field_link_abnlookup']); + } + } +}); + +jQuery(".abnlookup_field_setting input").click(function() { + if (jQuery(this).is(":checked")) { + SetFieldProperty('enable_abnlookup', 'true'); + SetFieldProperty('abnlookup_results_enable', ''); // force opposite value to off + } else { + SetFieldProperty('enable_abnlookup', ''); + } +}); + +jQuery(".abnlookup_entity_results_setting input").click(function() { + if (jQuery(this).is(":checked")) { + SetFieldProperty('abnlookup_results_enable', 'true'); + SetFieldProperty('enable_abnlookup', ''); // force opposite value to off + } else { + SetFieldProperty('abnlookup_results_enable', ''); + } +}); + +jQuery(".abnlookup_gst_field_setting input").click(function() { + if (jQuery(this).is(":checked")) { + SetFieldProperty('abnlookup_enable_gst', 'true'); + } else { + SetFieldProperty('abnlookup_enable_gst', ''); + } +}); + +jQuery(".abnlookup_business_name_field_setting input").click(function() { + if (jQuery(this).is(":checked")) { + SetFieldProperty('abnlookup_enable_business_name', 'true'); + } else { + SetFieldProperty('abnlookup_enable_business_name', ''); + } +}); + +jQuery('.abnlookup_entity_results_field_setting_text input').click(function() { + if (jQuery(this).is(":checked")) { + SetFieldProperty('abnlookup_results', jQuery(this).attr('id')); + } else { + SetFieldProperty('enable_results', ''); + } +}); + +jQuery('.abnlookup_entity_results_field_setting_date input').click(function() { + if (jQuery(this).is(":checked")) { + SetFieldProperty('abnlookup_results', jQuery(this).attr('id')); + } else { + SetFieldProperty('enable_results', ''); + } +}); + + +function itsg_gf_abnlookup_click_function(self) { + + if (typeof field == 'undefined') { + return; + } + + var abnlookup_enable_gst = (typeof field['abnlookup_enable_gst'] != 'undefined' && field['abnlookup_enable_gst'] != '') ? field['abnlookup_enable_gst'] : false; + var abnlookup_enable_business_name = (typeof field['abnlookup_enable_business_name'] != 'undefined' && field['abnlookup_enable_business_name'] != '') ? field['abnlookup_enable_business_name'] : false; + + if (abnlookup_enable_gst != false) { + //check the checkbox if previously checked + jQuery(self).find(".choices_setting:visible").hide(); + jQuery(self).find(".other_choice_setting:visible").hide(); + + jQuery(self).find(".ginput_container ul li:nth-child(1) label").text('Yes'); + jQuery(self).find(".ginput_container ul li:nth-child(2) label").text('No'); + jQuery(self).find(".ginput_container ul li:nth-child(n+3)").remove(); + } + + // handles displaying the 'Validate ABN Lookup field' select list + if (jQuery('input#field_enable_abnlookup:visible').is(":checked")) { + jQuery('.abnlookup_validate_field_setting').show(); // show validate options + jQuery('input#abnlookup_entity_results').prop('checked', false); // untick opposite option + } else { + jQuery('.abnlookup_validate_field_setting').hide(); // hide validate options + } + + // handles displaying the 'Entity results' radio list + if (jQuery('input#abnlookup_entity_results:visible').is(":checked")) { + jQuery('.abnlookup_entity_results_field_setting_' + field['type']).show(); // show entity result options + jQuery('.abnlookup_link_field_setting').show(); // show the 'Link ABN Field' setting + jQuery('input#field_enable_abnlookup').prop('checked', false); // untick opposite option + } else { + jQuery('.abnlookup_entity_results_field_setting_' + field['type']).hide(); // hide entity result options + jQuery('.abnlookup_link_field_setting').hide(); // hide the 'Link ABN Field' setting + } + + jQuery('input#field_enable_abnlookup_business_name:visible').each(function() { + if (jQuery(this).is(":checked")) { + jQuery(this).closest("ul").find('li.abnlookup_link_field_setting').show(); + } + }); + + // handles how the GST field is displayed if the GST option is enabled + jQuery('input#field_enable_abnlookup_gst:visible').each(function() { + if (jQuery(this).is(":checked")) { + + jQuery(this).closest("ul").find('li.abnlookup_link_field_setting').show(); // show the 'Link ABN Field' setting + + // hide the choices section + jQuery(this).closest("ul").find('.choices_setting').hide(); + jQuery(this).closest("ul").find('.other_choice_setting').hide(); + + // set the field options preview as 'yes' and 'no' -- the actual values are set using gform_pre_render + var override_input_value = ' \ +'; + jQuery(this).closest("li.gfield").find('.ginput_container_radio').html(override_input_value); + } else { + // hide the 'Link ABN Field' setting + jQuery(this).parent("li").next().hide(); + + // display the choices section + jQuery(this).closest("ul").find('.choices_setting').show(); + jQuery(this).closest("ul").find('.other_choice_setting').show(); + + // update the field option preview to what is contained in the choices setion + InsertFieldChoice(0); + DeleteFieldChoice(0); + } + }); + +} + +// trigger for when field is opened +jQuery(document).on('click', 'ul.gform_fields li.gfield', function() { + setTimeout(function() { + itsg_gf_abnlookup_click_function(jQuery(this)); + }, 500); +}); \ No newline at end of file diff --git a/tags/2.0.1/js/abnlookup-script-admin.min.js b/tags/2.0.1/js/abnlookup-script-admin.min.js new file mode 100644 index 0000000..a13b020 --- /dev/null +++ b/tags/2.0.1/js/abnlookup-script-admin.min.js @@ -0,0 +1 @@ +function itsg_gf_abnlookup_form_has_abnlookup(){for(var e in form.fields){if(form.fields.hasOwnProperty(e))if("true"==form.fields[e].enable_abnlookup)return!0}}function itsg_gf_abnlookup_click_function(e){if("undefined"!=typeof field){var i=void 0!==field.abnlookup_enable_gst&&""!=field.abnlookup_enable_gst&&field.abnlookup_enable_gst;void 0!==field.abnlookup_enable_business_name&&""!=field.abnlookup_enable_business_name&&field.abnlookup_enable_business_name;0!=i&&(jQuery(e).find(".choices_setting:visible").hide(),jQuery(e).find(".other_choice_setting:visible").hide(),jQuery(e).find(".ginput_container ul li:nth-child(1) label").text("Yes"),jQuery(e).find(".ginput_container ul li:nth-child(2) label").text("No"),jQuery(e).find(".ginput_container ul li:nth-child(n+3)").remove()),jQuery("input#field_enable_abnlookup:visible").is(":checked")?(jQuery(".abnlookup_validate_field_setting").show(),jQuery("input#abnlookup_entity_results").prop("checked",!1)):jQuery(".abnlookup_validate_field_setting").hide(),jQuery("input#abnlookup_entity_results:visible").is(":checked")?(jQuery(".abnlookup_entity_results_field_setting_"+field.type).show(),jQuery(".abnlookup_link_field_setting").show(),jQuery("input#field_enable_abnlookup").prop("checked",!1)):(jQuery(".abnlookup_entity_results_field_setting_"+field.type).hide(),jQuery(".abnlookup_link_field_setting").hide()),jQuery("input#field_enable_abnlookup_business_name:visible").each((function(){jQuery(this).is(":checked")&&jQuery(this).closest("ul").find("li.abnlookup_link_field_setting").show()})),jQuery("input#field_enable_abnlookup_gst:visible").each((function(){if(jQuery(this).is(":checked")){jQuery(this).closest("ul").find("li.abnlookup_link_field_setting").show(),jQuery(this).closest("ul").find(".choices_setting").hide(),jQuery(this).closest("ul").find(".other_choice_setting").hide();jQuery(this).closest("li.gfield").find(".ginput_container_radio").html('\ +
\ +- \ + \ + \ +
\ +- \ + \ + \ +
\ +\t\t\t\t\t\t\t')}else jQuery(this).parent("li").next().hide(),jQuery(this).closest("ul").find(".choices_setting").show(),jQuery(this).closest("ul").find(".other_choice_setting").show(),InsertFieldChoice(0),DeleteFieldChoice(0)}))}}jQuery(document).bind("gform_load_field_settings",(function(e,i,t){var l=i.type;if(itsg_gf_abnlookup_form_has_abnlookup()){if("text"==l){_=jQuery(".abnlookup_field_setting"),a=jQuery(".abnlookup_validate_field_setting"),d=jQuery(this).find(".abnlookup_link_field_setting"),p=jQuery(".abnlookup_entity_results_setting"),b=jQuery(".abnlookup_entity_results_field_setting_text");_.show(),p.show(),"true"==i.enable_abnlookup?(a.show(),d.hide(),p.hide(),b.hide()):(a.hide(),d.hide(),b.hide()),"true"==i.abnlookup_results_enable?(a.hide(),p.show(),b.show(),d.show()):(d.hide(),b.hide()),d.find("select option").remove();for(r=0;r\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t- \t\t\t\t\t\t\t\t\t \t\t\t\t\t\t\t\t\t \t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t\t- \t\t\t\t\t\t\t\t\t \t\t\t\t\t\t\t\t\t \t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t"+k+"")}c=void 0!==i.enable_abnlookup&&""!=i.enable_abnlookup&&i.enable_abnlookup,h=void 0!==i.abnlookup_results_enable&&""!=i.abnlookup_results_enable&&i.abnlookup_results_enable;0!=c?_.find("input:checkbox").prop("checked",!0):_.find("input:checkbox").prop("checked",!1),0!=h?p.find("input:checkbox").prop("checked",!0):p.find("input:checkbox").prop("checked",!1),void 0!==i.abnlookup_results&&b.find("input#"+i.abnlookup_results).prop("checked",!0),a.find("select").val(null==i.field_validate_abnlookup?"validabn":i.field_validate_abnlookup),d.find("select").val(null==i.field_link_abnlookup?"":i.field_link_abnlookup)}else if("select"==l){var n=jQuery(this).find(".abnlookup_business_name_field_setting");d=jQuery(this).find(".abnlookup_link_field_setting");n.show(),"true"==i.abnlookup_enable_business_name?d.show():d.hide();var o=void 0!==i.abnlookup_enable_business_name&&""!=i.abnlookup_enable_business_name&&i.abnlookup_enable_business_name;d.find("select option").remove();for(r=0;r "+k+"")}0!=o?n.find("input:checkbox").prop("checked",!0):n.find("input:checkbox").prop("checked",!1),d.find("select").val(null==i.field_link_abnlookup?"":i.field_link_abnlookup)}else if("radio"==l){var u=jQuery(this).find(".abnlookup_gst_field_setting");d=jQuery(this).find(".abnlookup_link_field_setting");u.show(),"true"==i.abnlookup_enable_gst?d.show():d.hide();var s=void 0!==i.abnlookup_enable_gst&&""!=i.abnlookup_enable_gst&&i.abnlookup_enable_gst;d.find("select option").remove();for(r=0;r "+k+"")}0!=s?u.find("input:checkbox").prop("checked",!0):u.find("input:checkbox").prop("checked",!1),d.find("select").val(null==i.field_link_abnlookup?"":i.field_link_abnlookup)}else if("date"==l){p=jQuery(".abnlookup_entity_results_setting"),d=jQuery(".abnlookup_link_field_setting"),b=jQuery(".abnlookup_entity_results_field_setting_date");p.show(),"true"==i.abnlookup_results_enable?(d.show(),b.show()):(d.hide(),b.hide()),d.find("select option").remove();for(r=0;r "+k+"")}0!=(h=void 0!==i.abnlookup_results_enable&&""!=i.abnlookup_results_enable&&i.abnlookup_results_enable)?p.find("input:checkbox").prop("checked",!0):p.find("input:checkbox").prop("checked",!1),void 0!==i.abnlookup_results&&b.find("input#"+i.abnlookup_results).prop("checked",!0),d.find("select").val(null==i.field_link_abnlookup?"":i.field_link_abnlookup)}}else if("text"==l){var _=jQuery(".abnlookup_field_setting"),a=jQuery(".abnlookup_validate_field_setting"),d=jQuery(this).find(".abnlookup_link_field_setting"),p=jQuery(".abnlookup_entity_results_setting"),b=jQuery(".abnlookup_entity_results_field_setting_text");_.show(),d.find("select option").remove();for(var r=0;r "+k+"")}var c=void 0!==i.enable_abnlookup&&""!=i.enable_abnlookup&&i.enable_abnlookup,h=void 0!==i.abnlookup_results_enable&&""!=i.abnlookup_results_enable&&i.abnlookup_results_enable;0!=c?_.find("input:checkbox").prop("checked",!0):_.find("input:checkbox").prop("checked",!1),0!=h?p.find("input:checkbox").prop("checked",!0):p.find("input:checkbox").prop("checked",!1),void 0!==i.abnlookup_results&&b.find("input#"+i.abnlookup_results).prop("checked",!0),a.find("select").val(null==i.field_validate_abnlookup?"validabn":i.field_validate_abnlookup),d.find("select").val(null==i.field_link_abnlookup?"":i.field_link_abnlookup)}})),jQuery(".abnlookup_field_setting input").click((function(){jQuery(this).is(":checked")?(SetFieldProperty("enable_abnlookup","true"),SetFieldProperty("abnlookup_results_enable","")):SetFieldProperty("enable_abnlookup","")})),jQuery(".abnlookup_entity_results_setting input").click((function(){jQuery(this).is(":checked")?(SetFieldProperty("abnlookup_results_enable","true"),SetFieldProperty("enable_abnlookup","")):SetFieldProperty("abnlookup_results_enable","")})),jQuery(".abnlookup_gst_field_setting input").click((function(){jQuery(this).is(":checked")?SetFieldProperty("abnlookup_enable_gst","true"):SetFieldProperty("abnlookup_enable_gst","")})),jQuery(".abnlookup_business_name_field_setting input").click((function(){jQuery(this).is(":checked")?SetFieldProperty("abnlookup_enable_business_name","true"):SetFieldProperty("abnlookup_enable_business_name","")})),jQuery(".abnlookup_entity_results_field_setting_text input").click((function(){jQuery(this).is(":checked")?SetFieldProperty("abnlookup_results",jQuery(this).attr("id")):SetFieldProperty("enable_results","")})),jQuery(".abnlookup_entity_results_field_setting_date input").click((function(){jQuery(this).is(":checked")?SetFieldProperty("abnlookup_results",jQuery(this).attr("id")):SetFieldProperty("enable_results","")})),jQuery(document).on("click","ul.gform_fields li.gfield",(function(){setTimeout((function(){itsg_gf_abnlookup_click_function(jQuery(this))}),500)})); \ No newline at end of file diff --git a/tags/2.0.1/js/abnlookup-script.js b/tags/2.0.1/js/abnlookup-script.js new file mode 100644 index 0000000..aa1f82b --- /dev/null +++ b/tags/2.0.1/js/abnlookup-script.js @@ -0,0 +1,382 @@ + +text/x-generic abnlookup-script.js ( ASCII text ) +function itsg_gf_abnlookup_function( field_id, field_validate_abnlookup, field_dateFormat ){ + var ajax_url = gf_abnlookup_settings.ajax_url; + var validation_message_loading = gf_abnlookup_settings.validation_message_loading; + var validation_message_not_valid = gf_abnlookup_settings.validation_message_not_valid; + var validation_message_error_communicating = gf_abnlookup_settings.validation_message_error_communicating; + var validation_message_11_char = gf_abnlookup_settings.validation_message_11_char; + var text_checking = gf_abnlookup_settings.text_checking; + var text_check_abn = gf_abnlookup_settings.text_check_abn; + var gst_value_yes = gf_abnlookup_settings.gst_value_yes; + var gst_value_no = gf_abnlookup_settings.gst_value_no; + var lookup_timeout = gf_abnlookup_settings.lookup_timeout; + var lookup_retries = gf_abnlookup_settings.lookup_retries; + + (function( $ ) { + "use strict"; + var checkABR = function( data ){ + var request = $.ajax({ + type: 'POST', + url: ajax_url, + data: data, + tryCount : 0, + retryLimit : lookup_retries, + beforeSend: function(){ + gform_validation_message.hide(); + itsg_abnlookup_response.html( validation_message_loading ); + itsg_abnlookup_checkabn_button.val( text_checking + ' ... ' ); + itsg_abnlookup_response.addClass( 'loading' ); + itsg_abnlookup_response.removeClass( 'error Active Cancelled validation_message' ); + }, + success: function(response){ + if(typeof response !== 'undefined' ){ + try { + // console.log (response); + itsg_abnlookup_checkabn_button.val( text_check_abn ); + var result = JSON.parse(response); + if ( result["exception"] != undefined ) { + gform_validation_message.hide(); + if ( 'Search text is not a valid ABN or ACN' == result['exception']['exceptionDescription'] ) { + itsg_abnlookup_response.html( validation_message_not_valid ); + } else { + itsg_abnlookup_response.text( result['exception']['exceptionDescription'] ); + } + itsg_abnlookup_response.removeClass( 'Active Cancelled loading' ); + itsg_abnlookup_response.addClass( 'error validation_message' ); + gform_abnlookup_entity_gst_field.hide(); + gform_abnlookup_entity_type_field.hide(); + gform_abnlookup_entity_status_field.hide(); + gform_abnlookup_entity_name_field.hide(); + gform_abnlookup_entity_postcode_field.hide(); + gform_abnlookup_entity_state_field.hide(); + gform_abnlookup_entity_effective_from.hide(); + gform_abnlookup_gst_effective_from.hide(); + gform_abnlookup_business_name.hide(); + gform_abnlookup_entity_type_field_input.val('').change(); + gform_abnlookup_entity_status_field_input.val('').change(); + gform_abnlookup_entity_name_field_input.val('').change(); + gform_abnlookup_entity_postcode_field_input.val('').change(); + gform_abnlookup_entity_state_field_input.val('').change(); + gform_abnlookup_entity_effective_from_input.val('').change(); + gform_abnlookup_gst_effective_from_input.val('').change(); + jQuery('.gform_abnlookup_business_name_field_' + field_id + ' option').remove(); + gform_abnlookup_entity_gst_field_yes.prop( 'disabled', false ); + gform_abnlookup_entity_gst_field_no.prop( 'disabled', false ); + gform_abnlookup_entity_gst_field_yes.prop( 'checked', false ).change().keyup(); + gform_abnlookup_entity_gst_field_no.prop( 'checked', false ).change().keyup(); + gform_abnlookup_entity_type_field_input.prop( 'readonly', false ); + gform_abnlookup_entity_status_field_input.prop( 'readonly', false ); + gform_abnlookup_entity_name_field_input.prop( 'readonly', false ); + gform_abnlookup_entity_postcode_field_input.prop( 'readonly', false ); + gform_abnlookup_entity_state_field_input.prop( 'readonly', false ); + gform_abnlookup_entity_effective_from_input.prop( 'readonly', false ); + gform_abnlookup_gst_effective_from_input.prop( 'readonly', false ); + } else if ( result['businessEntity202001'] != undefined ) { + // console.log(result['businessEntity202001']); + var entityTypeCode = result['businessEntity202001']['entityType']['entityTypeCode']; + var entityType = result['businessEntity202001']['entityType']['entityDescription']; + var entityStatus = result['businessEntity202001']['entityStatus']['entityStatusCode']; + var entityPostcode = result['businessEntity202001']['mainBusinessPhysicalAddress']['postcode']; + var entityState = result['businessEntity202001']['mainBusinessPhysicalAddress']['stateCode']; + var entityEffectiveFrom = result['businessEntity202001']['entityStatus']['effectiveFrom']; + var businessNames = result['businessEntity202001']['businessName']; + // format the date to match the field format + var date = new Date( entityEffectiveFrom ); + var day = ( '0' + date.getDate() ).slice(-2); + var month = ( '0' + ( date.getMonth() + 1 ) ).slice(-2); + var year = date.getFullYear(); + // get date format + if ( gform_abnlookup_entity_effective_from_input.hasClass('dmy') ) { + var entityEffectiveFromFormatted = day + '/' + month + '/' + year; + } else if ( gform_abnlookup_entity_effective_from_input.hasClass('dmy_dash') ) { + var entityEffectiveFromFormatted = day + '-' + month + '-' + year; + } else if ( gform_abnlookup_entity_effective_from_input.hasClass('dmy_dot') ) { + var entityEffectiveFromFormatted = day + '.' + month + '.' + year; + } else if ( gform_abnlookup_entity_effective_from_input.hasClass('ymd_slash') ) { + var entityEffectiveFromFormatted = year + '/' + month + '/' + date; + } else if ( gform_abnlookup_entity_effective_from_input.hasClass('ymd_dash') ) { + var entityEffectiveFromFormatted = year + '-' + month + '-' + date; + } else if ( gform_abnlookup_entity_effective_from_input.hasClass('ymd_dot') ) { + var entityEffectiveFromFormatted = year + '.' + month + '.' + date; + } else { + var entityEffectiveFromFormatted = month + '/' + day + '/' + year; + } + + if ( result['businessEntity202001']['goodsAndServicesTax'] != undefined ) { + var GSTEffectiveFrom = result['businessEntity202001']['goodsAndServicesTax']['effectiveFrom']; + // format the date to match the field format + var date = new Date( GSTEffectiveFrom ); + var day = ( '0' + date.getDate() ).slice(-2); + var month = ( '0' + ( date.getMonth() + 1 ) ).slice(-2); + var year = date.getFullYear(); + // get date format + if ( gform_abnlookup_entity_effective_from_input.hasClass('dmy') ) { + var GSTEffectiveFromFormatted = day + '/' + month + '/' + year; + } else if ( gform_abnlookup_gst_effective_from_input.hasClass('dmy_dash') ) { + var GSTEffectiveFromFormatted = day + '-' + month + '-' + year; + } else if ( gform_abnlookup_gst_effective_from_input.hasClass('dmy_dot') ) { + var GSTEffectiveFromFormatted = day + '.' + month + '.' + year; + } else if ( gform_abnlookup_gst_effective_from_input.hasClass('ymd_slash') ) { + var GSTEffectiveFromFormatted = year + '/' + month + '/' + date; + } else if ( gform_abnlookup_gst_effective_from_input.hasClass('ymd_dash') ) { + var GSTEffectiveFromFormatted = year + '-' + month + '-' + date; + } else if ( gform_abnlookup_gst_effective_from_input.hasClass('ymd_dot') ) { + var GSTEffectiveFromFormatted = year + '.' + month + '.' + date; + } else { + var GSTEffectiveFromFormatted = month + '/' + day + '/' + year; + } + + gform_abnlookup_gst_effective_from_input.val( GSTEffectiveFromFormatted ).change(); + gform_abnlookup_gst_effective_from_input.prop( 'readonly', true ); + gform_abnlookup_gst_effective_from.show(); + } else { + gform_abnlookup_gst_effective_from.hide(); + gform_abnlookup_gst_effective_from_input.val('').change(); + } + + if ( entityTypeCode == 'IND' ) { + var familyName = 'string' == typeof result['businessEntity202001']['legalName']['familyName'] ? result['businessEntity202001']['legalName']['familyName'] : ''; + var givenName = 'string' == typeof result['businessEntity202001']['legalName']['givenName'] ? result['businessEntity202001']['legalName']['givenName'] : ''; + var otherGivenName = 'string' == typeof result['businessEntity202001']['legalName']["otherGivenName"] ? result['businessEntity202001']['legalName']["otherGivenName"] : ''; + var entityName = familyName + ", " + givenName + " " + otherGivenName; + } else { + var entityName = result['businessEntity202001']['mainName']['organisationName']; + } + + if (typeof businessNames !== 'undefined') { + console.log(businessNames); + jQuery('.gform_abnlookup_business_name_field_' + field_id + ' option').remove(); + var entityNameOption = new Option(entityName, entityName, true, true); + gform_abnlookup_business_name_select.append(entityNameOption); + if (businessNames.length) { + businessNames.forEach(function(item, index, arr) { + var thisNameOption = new Option(item['organisationName'], item['organisationName'], false, false); + gform_abnlookup_business_name_select.append(thisNameOption); + }); + } else { + var thisNameOption = new Option(businessNames['organisationName'], businessNames['organisationName'], false, false); + gform_abnlookup_business_name_select.append(thisNameOption); + } + } else { + jQuery('.gform_abnlookup_business_name_field_' + field_id + ' option').remove(); + var entityNameOption = new Option(entityName, entityName, true, true); + gform_abnlookup_business_name_select.append(entityNameOption); + } + + gform_validation_message.hide(); + itsg_abnlookup_response.text( entityStatus + ' - ' + entityName ); + gform_abnlookup_entity_type_field_input.val( entityType ).change(); + gform_abnlookup_entity_type_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_status_field_input.val( entityStatus ).change(); + gform_abnlookup_entity_status_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_name_field_input.val( entityName ).change(); + gform_abnlookup_entity_name_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_postcode_field_input.val( entityPostcode ).change(); + gform_abnlookup_entity_postcode_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_state_field_input.val( entityState ).change(); + gform_abnlookup_entity_state_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_effective_from_input.val( entityEffectiveFromFormatted ).change(); + gform_abnlookup_entity_effective_from_input.prop( 'readonly', true ); + itsg_abnlookup_response.removeClass( 'error loading validation_message' ); + itsg_abnlookup_response.addClass( entityStatus ); + if (result['businessEntity202001']['goodsAndServicesTax'] != undefined && result['businessEntity202001']['goodsAndServicesTax']['effectiveTo'] == '0001-01-01' ) { + gform_abnlookup_entity_gst_field_yes.prop( 'checked', true ).click().change().keyup(); + gform_abnlookup_entity_gst_field_yes.prop( 'disabled', false ); + gform_abnlookup_entity_gst_field_no.prop( 'disabled', true ); + } else { + gform_abnlookup_entity_gst_field_no.prop( 'checked', true ).click().change().keyup(); + gform_abnlookup_entity_gst_field_no.prop( 'disabled', false ); + gform_abnlookup_entity_gst_field_yes.prop( 'disabled', true ); + } + gform_abnlookup_entity_gst_field.show(); + gform_abnlookup_entity_type_field.show(); + gform_abnlookup_entity_name_field.show(); + gform_abnlookup_entity_status_field.show(); + gform_abnlookup_entity_postcode_field.show(); + gform_abnlookup_entity_state_field.show(); + gform_abnlookup_entity_effective_from.show(); + gform_abnlookup_business_name.show(); + } + } catch( error ){ + // console.log( response ); + itsg_abnlookup_response.text( error ); + itsg_abnlookup_response.removeClass( 'loading Active Cancelled' ); + itsg_abnlookup_response.addClass( 'error validation_message' ); + } + } + }, + error: function ( request, status, error ) { + if ( 'timeout' == status ) { + this.tryCount++; + if ( this.tryCount <= this.retryLimit ) { + //try again + $.ajax( this ); + return; + } + itsg_abnlookup_response.text( validation_message_error_communicating ); + } else { + itsg_abnlookup_response.text( request.responseText ); + } + itsg_abnlookup_checkabn_button.val( text_check_abn ); + itsg_abnlookup_response.removeClass( 'loading Active Cancelled' ); + itsg_abnlookup_response.addClass( 'error validation_message' ); + }, + timeout: lookup_timeout // set timeout to 5 seconds + }); + return request; + }; + + var request = false; + + var gform_abnlookup_field = jQuery( '.gform_abnlookup_field_' + field_id + ' input[type="text"]' ); + var gform_validation_message = jQuery( '.gform_abnlookup_field_' + field_id + ' .gfield_description.validation_message' ); + var itsg_abnlookup_response = jQuery( '.itsg_abnlookup_response_' + field_id + '' ); + var itsg_abnlookup_checkabn_button = jQuery( '.itsg_abnlookup_checkabn_' + field_id + '' ); + var gform_abnlookup_entity_gst_field = jQuery( '.gform_abnlookup_entity_gst_field_' + field_id + '' ); + var gform_abnlookup_entity_gst_field_yes = jQuery( '.gform_abnlookup_entity_gst_field_' + field_id + ' input[value="' + gst_value_yes + '"]' ); + var gform_abnlookup_entity_gst_field_no = jQuery( '.gform_abnlookup_entity_gst_field_' + field_id + ' input[value="' + gst_value_no + '"]' ); + var gform_abnlookup_entity_type_field = jQuery( '.gform_abnlookup_entity_type_field_' + field_id + '' ); + var gform_abnlookup_entity_type_field_input = jQuery( '.gform_abnlookup_entity_type_field_' + field_id + ' input' ); + var gform_abnlookup_entity_status_field = jQuery( '.gform_abnlookup_entity_status_field_' + field_id + '' ); + var gform_abnlookup_entity_status_field_input = jQuery( '.gform_abnlookup_entity_status_field_' + field_id + ' input' ); + var gform_abnlookup_entity_name_field = jQuery( '.gform_abnlookup_entity_name_field_' + field_id + '' ); + var gform_abnlookup_entity_name_field_input = jQuery( '.gform_abnlookup_entity_name_field_' + field_id + ' input' ); + var gform_abnlookup_entity_postcode_field = jQuery( '.gform_abnlookup_entity_postcode_field_' + field_id + '' ); + var gform_abnlookup_entity_postcode_field_input = jQuery( '.gform_abnlookup_entity_postcode_field_' + field_id + ' input' ); + var gform_abnlookup_entity_state_field = jQuery( '.gform_abnlookup_entity_state_field_' + field_id + '' ); + var gform_abnlookup_entity_state_field_input = jQuery( '.gform_abnlookup_entity_state_field_' + field_id + ' input' ); + var gform_abnlookup_entity_effective_from = jQuery( '.gform_abnlookup_entity_effective_from_field_' + field_id + '' ); + var gform_abnlookup_entity_effective_from_input = jQuery( '.gform_abnlookup_entity_effective_from_field_' + field_id + ' input' ); + var gform_abnlookup_gst_effective_from = jQuery( '.gform_abnlookup_gst_effective_from_field_' + field_id + '' ); + var gform_abnlookup_gst_effective_from_input = jQuery( '.gform_abnlookup_gst_effective_from_field_' + field_id + ' input' ); + var gform_abnlookup_business_name = jQuery( '.gform_abnlookup_business_name_field_' + field_id + '' ); + var gform_abnlookup_business_name_select = jQuery( '.gform_abnlookup_business_name_field_' + field_id + ' select' ); + var gform_abnlookup_business_name_options = jQuery( '.gform_abnlookup_business_name_field_' + field_id + ' option' ); + + if ( '' !== itsg_abnlookup_response.html() ) { + + // if pre-filled fields are empty - trigger ABN Lookup + if ( ( gform_abnlookup_entity_gst_field_yes.is( ':visible' ) + && true != gform_abnlookup_entity_gst_field_yes.prop( 'checked' ) + && true != gform_abnlookup_entity_gst_field_no.prop( 'checked' ) ) + || ( gform_abnlookup_entity_type_field_input.is( ':visible' ) + && '' == gform_abnlookup_entity_type_field_input.val() ) + || ( gform_abnlookup_entity_status_field_input.is( ':visible' ) + && '' == gform_abnlookup_entity_status_field_input.val() ) + || ( gform_abnlookup_entity_name_field_input.is( ':visible' ) + && '' == gform_abnlookup_entity_name_field_input.val() ) + || ( gform_abnlookup_entity_postcode_field_input.is( ':visible' ) + && '' == gform_abnlookup_entity_postcode_field_input.val() ) + || ( gform_abnlookup_entity_state_field_input.is( ':visible' ) + && '' == gform_abnlookup_entity_state_field_input.val() ) + || ( gform_abnlookup_entity_effective_from_input.is( ':visible' ) + && '' == gform_abnlookup_entity_effective_from_input.val() ) + || ( gform_abnlookup_business_name_select.is( ':visible' ) + && '' == gform_abnlookup_business_name_select.val() ) + || ( gform_abnlookup_gst_effective_from_input.is( ':visible' ) + && '' == gform_abnlookup_gst_effective_from_input.val() ) ) { + gform_abnlookup_field.trigger( 'change' ); + } + + // disable GST field that isnt currently used + if ( gform_abnlookup_entity_gst_field_yes.is( ':checked' ) ) { + gform_abnlookup_entity_gst_field_no.prop( 'disabled', true ); + } else if ( gform_abnlookup_entity_gst_field_no.is( ':checked' ) ) { + gform_abnlookup_entity_gst_field_yes.prop( 'disabled', true ); + } + + // set fields to read only + gform_abnlookup_entity_type_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_status_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_name_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_postcode_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_state_field_input.prop( 'readonly', true ); + gform_abnlookup_entity_effective_from_input.prop( 'readonly', true ); + gform_abnlookup_gst_effective_from_input.prop( 'readonly', true ); + } else { + + // hide linked fields + gform_abnlookup_entity_gst_field.closest( 'li.gfield' ).hide() + gform_abnlookup_entity_type_field.closest( 'li.gfield' ).hide(); + gform_abnlookup_entity_status_field.closest( 'li.gfield' ).hide(); + gform_abnlookup_entity_name_field.closest( 'li.gfield' ).hide(); + gform_abnlookup_entity_postcode_field.closest( 'li.gfield' ).hide(); + gform_abnlookup_entity_state_field.closest( 'li.gfield' ).hide(); + gform_abnlookup_entity_effective_from.closest( 'li.gfield' ).hide(); + gform_abnlookup_gst_effective_from.closest( 'li.gfield' ).hide(); + gform_abnlookup_business_name.closest( 'li.gfield' ).hide(); + } + + gform_abnlookup_field.unbind( 'change' ).change( function() { + var numbersOnly = jQuery( this ).val().replace(/\D/g, '' ); + if ( 11 == numbersOnly.length ) { + // console.log( numbersOnly ); + var abn = numbersOnly; + var data = { + 'action': 'itsg_gf_abnlookup_check_ajax', + 'abn': abn + }; + if( request && 4 !== request.readyState ){ + // console.log( 'Abort! -- another request has been submitted.' ) + request.abort(); + } + + request = checkABR( data ); + } else { + gform_abnlookup_entity_gst_field.hide(); + gform_abnlookup_entity_type_field.hide(); + gform_abnlookup_entity_status_field.hide(); + gform_abnlookup_entity_name_field.hide(); + gform_abnlookup_entity_postcode_field.hide(); + gform_abnlookup_entity_state_field.hide(); + gform_abnlookup_entity_effective_from.hide(); + gform_abnlookup_gst_effective_from.hide(); + gform_abnlookup_business_name.hide(); + gform_abnlookup_entity_type_field_input.val('').change(); + gform_abnlookup_entity_status_field_input.val('').change(); + gform_abnlookup_entity_name_field_input.val('').change(); + gform_abnlookup_entity_postcode_field_input.val('').change(); + gform_abnlookup_entity_state_field_input.val('').change(); + gform_abnlookup_entity_effective_from_input.val('').change(); + jQuery('.gform_abnlookup_business_name_field_' + field_id + ' option').remove(); + gform_abnlookup_gst_effective_from_input.val('').change(); + gform_abnlookup_entity_gst_field_yes.prop( 'disabled', false ); + gform_abnlookup_entity_gst_field_no.prop( 'disabled', false ); + gform_abnlookup_entity_gst_field_yes.prop( 'checked', false ).change().keyup(); + gform_abnlookup_entity_gst_field_no.prop( 'checked', false ).change().keyup(); + gform_validation_message.hide(); + itsg_abnlookup_response.html( validation_message_11_char ); + itsg_abnlookup_response.addClass( 'error validation_message' ); + itsg_abnlookup_response.removeClass( 'loading Active Cancelled' ); + } + }); + }( jQuery )); +} + +jQuery(document).ready(function($){ + var abnlookup_fields = gf_abnlookup_settings.abnlookup_fields; + var form_id = gf_abnlookup_settings.form_id; + for ( var key in abnlookup_fields ){ + var field_id = key; + jQuery( '#input_' + form_id + '_' + field_id ).unbind( 'keydown' ).keydown( function( event ) { + if ( 13 == event.which || 13 == event.keyCode ) { + event.preventDefault(); + jQuery( this ).trigger( 'change' ); + } + }); + jQuery( '#input_' + form_id + '_' + field_id ).unbind( 'keyup' ).keyup( function( event ) { + if ( 13 == event.which || 13 == event.keyCode ) { + event.preventDefault(); + } + }); + jQuery( '#input_' + form_id + '_' + field_id ).on('change keyup', function($){ + var field_validate_abnlookup = abnlookup_fields[ key ]['validate']; + var field_dateFormat = abnlookup_fields[ key ]['dateFormat']; + if( typeof field_validate_abnlookup !== 'undefined' ) { + //console.log( 'abn-lookup-for-gravity-forms :: field_id: ' + field_id + ' field_validate_abnlookup: ' + field_validate_abnlookup + ' field_dateFormat: ' + field_dateFormat ); + itsg_gf_abnlookup_function( field_id, field_validate_abnlookup, field_dateFormat ); + } + }); + } +}); \ No newline at end of file diff --git a/tags/2.0.1/js/abnlookup-script.min.js b/tags/2.0.1/js/abnlookup-script.min.js new file mode 100644 index 0000000..8ac4a51 --- /dev/null +++ b/tags/2.0.1/js/abnlookup-script.min.js @@ -0,0 +1 @@ +function itsg_gf_abnlookup_function(e,i,a){var o=gf_abnlookup_settings.ajax_url,n=gf_abnlookup_settings.validation_message_loading,s=gf_abnlookup_settings.validation_message_not_valid,t=gf_abnlookup_settings.validation_message_error_communicating,l=gf_abnlookup_settings.validation_message_11_char,r=gf_abnlookup_settings.text_checking,d=gf_abnlookup_settings.text_check_abn,_=gf_abnlookup_settings.gst_value_yes,p=gf_abnlookup_settings.gst_value_no,u=gf_abnlookup_settings.lookup_timeout,g=gf_abnlookup_settings.lookup_retries;!function(i){"use strict";var a=!1,y=jQuery(".gform_abnlookup_field_"+e+' input[type="text"]'),c=jQuery(".gform_abnlookup_field_"+e+" .gfield_description.validation_message"),f=jQuery(".itsg_abnlookup_response_"+e),h=jQuery(".itsg_abnlookup_checkabn_"+e),v=jQuery(".gform_abnlookup_entity_gst_field_"+e),m=jQuery(".gform_abnlookup_entity_gst_field_"+e+' input[value="'+_+'"]'),b=jQuery(".gform_abnlookup_entity_gst_field_"+e+' input[value="'+p+'"]'),k=jQuery(".gform_abnlookup_entity_type_field_"+e),j=jQuery(".gform_abnlookup_entity_type_field_"+e+" input"),C=jQuery(".gform_abnlookup_entity_status_field_"+e),Q=jQuery(".gform_abnlookup_entity_status_field_"+e+" input"),x=jQuery(".gform_abnlookup_entity_name_field_"+e),N=jQuery(".gform_abnlookup_entity_name_field_"+e+" input"),E=jQuery(".gform_abnlookup_entity_postcode_field_"+e),w=jQuery(".gform_abnlookup_entity_postcode_field_"+e+" input"),A=jQuery(".gform_abnlookup_entity_state_field_"+e),S=jQuery(".gform_abnlookup_entity_state_field_"+e+" input"),D=jQuery(".gform_abnlookup_entity_effective_from_field_"+e),T=jQuery(".gform_abnlookup_entity_effective_from_field_"+e+" input"),O=jQuery(".gform_abnlookup_gst_effective_from_field_"+e),F=jQuery(".gform_abnlookup_gst_effective_from_field_"+e+" input"),B=jQuery(".gform_abnlookup_business_name_field_"+e),P=jQuery(".gform_abnlookup_business_name_field_"+e+" select");jQuery(".gform_abnlookup_business_name_field_"+e+" option");""!==f.html()?((m.is(":visible")&&1!=m.prop("checked")&&1!=b.prop("checked")||j.is(":visible")&&""==j.val()||Q.is(":visible")&&""==Q.val()||N.is(":visible")&&""==N.val()||w.is(":visible")&&""==w.val()||S.is(":visible")&&""==S.val()||T.is(":visible")&&""==T.val()||P.is(":visible")&&""==P.val()||F.is(":visible")&&""==F.val())&&y.trigger("change"),m.is(":checked")?b.prop("disabled",!0):b.is(":checked")&&m.prop("disabled",!0),j.prop("readonly",!0),Q.prop("readonly",!0),N.prop("readonly",!0),w.prop("readonly",!0),S.prop("readonly",!0),T.prop("readonly",!0),F.prop("readonly",!0)):(v.closest("li.gfield").hide(),k.closest("li.gfield").hide(),C.closest("li.gfield").hide(),x.closest("li.gfield").hide(),E.closest("li.gfield").hide(),A.closest("li.gfield").hide(),D.closest("li.gfield").hide(),O.closest("li.gfield").hide(),B.closest("li.gfield").hide()),y.unbind("change").change((function(){var _=jQuery(this).val().replace(/\D/g,"");if(11==_.length){var p={action:"itsg_gf_abnlookup_check_ajax",abn:_};a&&4!==a.readyState&&a.abort(),a=function(a){return i.ajax({type:"POST",url:o,data:a,tryCount:0,retryLimit:g,beforeSend:function(){c.hide(),f.html(n),h.val(r+" ... "),f.addClass("loading"),f.removeClass("error Active Cancelled validation_message")},success:function(i){if(void 0!==i)try{h.val(d);var a=JSON.parse(i);if(null!=a.exception)c.hide(),"Search text is not a valid ABN or ACN"==a.exception.exceptionDescription?f.html(s):f.text(a.exception.exceptionDescription),f.removeClass("Active Cancelled loading"),f.addClass("error validation_message"),v.hide(),k.hide(),C.hide(),x.hide(),E.hide(),A.hide(),D.hide(),O.hide(),B.hide(),j.val("").change(),Q.val("").change(),N.val("").change(),w.val("").change(),S.val("").change(),T.val("").change(),F.val("").change(),jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),m.prop("disabled",!1),b.prop("disabled",!1),m.prop("checked",!1).change().keyup(),b.prop("checked",!1).change().keyup(),j.prop("readonly",!1),Q.prop("readonly",!1),N.prop("readonly",!1),w.prop("readonly",!1),S.prop("readonly",!1),T.prop("readonly",!1),F.prop("readonly",!1);else if(null!=a.businessEntity202001){var o=a.businessEntity202001.entityType.entityTypeCode,n=a.businessEntity202001.entityType.entityDescription,t=a.businessEntity202001.entityStatus.entityStatusCode,l=a.businessEntity202001.mainBusinessPhysicalAddress.postcode,r=a.businessEntity202001.mainBusinessPhysicalAddress.stateCode,_=a.businessEntity202001.entityStatus.effectiveFrom,p=a.businessEntity202001.businessName,u=("0"+(L=new Date(_)).getDate()).slice(-2),g=("0"+(L.getMonth()+1)).slice(-2),y=L.getFullYear();if(T.hasClass("dmy"))var G=u+"/"+g+"/"+y;else G=T.hasClass("dmy_dash")?u+"-"+g+"-"+y:T.hasClass("dmy_dot")?u+"."+g+"."+y:T.hasClass("ymd_slash")?y+"/"+g+"/"+L:T.hasClass("ymd_dash")?y+"-"+g+"-"+L:T.hasClass("ymd_dot")?y+"."+g+"."+L:g+"/"+u+"/"+y;if(null!=a.businessEntity202001.goodsAndServicesTax){var L,M=a.businessEntity202001.goodsAndServicesTax.effectiveFrom;if(u=("0"+(L=new Date(M)).getDate()).slice(-2),g=("0"+(L.getMonth()+1)).slice(-2),y=L.getFullYear(),T.hasClass("dmy"))var Y=u+"/"+g+"/"+y;else Y=F.hasClass("dmy_dash")?u+"-"+g+"-"+y:F.hasClass("dmy_dot")?u+"."+g+"."+y:F.hasClass("ymd_slash")?y+"/"+g+"/"+L:F.hasClass("ymd_dash")?y+"-"+g+"-"+L:F.hasClass("ymd_dot")?y+"."+g+"."+L:g+"/"+u+"/"+y;F.val(Y).change(),F.prop("readonly",!0),O.show()}else O.hide(),F.val("").change();if("IND"==o)var I=("string"==typeof a.businessEntity202001.legalName.familyName?a.businessEntity202001.legalName.familyName:"")+", "+("string"==typeof a.businessEntity202001.legalName.givenName?a.businessEntity202001.legalName.givenName:"")+" "+("string"==typeof a.businessEntity202001.legalName.otherGivenName?a.businessEntity202001.legalName.otherGivenName:"");else I=a.businessEntity202001.mainName.organisationName;if(void 0!==p){console.log(p),jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove();var J=new Option(I,I,!0,!0);if(P.append(J),p.length)p.forEach((function(e,i,a){var o=new Option(e.organisationName,e.organisationName,!1,!1);P.append(o)}));else{var q=new Option(p.organisationName,p.organisationName,!1,!1);P.append(q)}}else jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),J=new Option(I,I,!0,!0),P.append(J);c.hide(),f.text(t+" - "+I),j.val(n).change(),j.prop("readonly",!0),Q.val(t).change(),Q.prop("readonly",!0),N.val(I).change(),N.prop("readonly",!0),w.val(l).change(),w.prop("readonly",!0),S.val(r).change(),S.prop("readonly",!0),T.val(G).change(),T.prop("readonly",!0),f.removeClass("error loading validation_message"),f.addClass(t),null!=a.businessEntity202001.goodsAndServicesTax&&"0001-01-01"==a.businessEntity202001.goodsAndServicesTax.effectiveTo?(m.prop("checked",!0).click().change().keyup(),m.prop("disabled",!1),b.prop("disabled",!0)):(b.prop("checked",!0).click().change().keyup(),b.prop("disabled",!1),m.prop("disabled",!0)),v.show(),k.show(),x.show(),C.show(),E.show(),A.show(),D.show(),B.show()}}catch(e){f.text(e),f.removeClass("loading Active Cancelled"),f.addClass("error validation_message")}},error:function(e,a,o){if("timeout"==a){if(this.tryCount++,this.tryCount<=this.retryLimit)return void i.ajax(this);f.text(t)}else f.text(e.responseText);h.val(d),f.removeClass("loading Active Cancelled"),f.addClass("error validation_message")},timeout:u})}(p)}else v.hide(),k.hide(),C.hide(),x.hide(),E.hide(),A.hide(),D.hide(),O.hide(),B.hide(),j.val("").change(),Q.val("").change(),N.val("").change(),w.val("").change(),S.val("").change(),T.val("").change(),jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),F.val("").change(),m.prop("disabled",!1),b.prop("disabled",!1),m.prop("checked",!1).change().keyup(),b.prop("checked",!1).change().keyup(),c.hide(),f.html(l),f.addClass("error validation_message"),f.removeClass("loading Active Cancelled")}))}(jQuery)}jQuery(document).ready((function(e){var i=gf_abnlookup_settings.abnlookup_fields,a=gf_abnlookup_settings.form_id;for(var o in i){var n=o;jQuery("#input_"+a+"_"+n).unbind("keydown").keydown((function(e){13!=e.which&&13!=e.keyCode||(e.preventDefault(),jQuery(this).trigger("change"))})),jQuery("#input_"+a+"_"+n).unbind("keyup").keyup((function(e){13!=e.which&&13!=e.keyCode||e.preventDefault()})),jQuery("#input_"+a+"_"+n).on("change keyup",(function(e){var a=i[o].validate,s=i[o].dateFormat;void 0!==a&&itsg_gf_abnlookup_function(n,a,s)}))}})); \ No newline at end of file diff --git a/tags/2.0.1/readme.txt b/tags/2.0.1/readme.txt new file mode 100644 index 0000000..e474af8 --- /dev/null +++ b/tags/2.0.1/readme.txt @@ -0,0 +1,221 @@ +=== ABN Lookup for Gravity Forms === +Contributors: bakkbone,ovann86 +Donate link: https://ko-fi.com/bakkbone_scott +Tags: gravity forms, forms, ajax, abn, australian business number, australian business register +Requires at least: 6.0 +Tested up to: 6.4 +Requires PHP: 7.4 +Stable tag: 2.0.1 +License: GNU General Public License (GPL) 3.0 +License URI: https://www.gnu.org/licenses/gpl.html + +Integrate the Australian Business Register ABN Lookup tool in Gravity Forms + +== Description == + +> This plugin is an add-on for the Gravity Forms plugin. If you don't yet own a license for Gravity Forms - buy one now! (affiliate link) + +### What does this plugin do? + +* connect your forms to the [Australian Business Register ABN Lookup tool](http://abr.business.gov.au "Australian Business Register website") +* verify the ABN status and entity details +* pre-fill ABN status, entity name, entity type, location, GST status, GST registered date, entity date, business names into form fields +* use conditional logic and validation to enforce which entities can complete your form + +Includes an **easy to use settings page** that allows you to configure: + +* enter your unique GUID (necessary to use the plugin features - provided by the Australian Business Register, see [web services registration](http://abr.business.gov.au/webservices.aspx "Australian Business Register web services registration website")) +* disable plugin CSS styles - allowing you to create your own styles +* customise error messages and prompts displayed to form users + +> See a demo of this plugin at [staging.bkbn.au/abn-lookup-for-gravity-forms](https://staging.bkbn.au/abn-lookup-for-gravity-forms/ "Demonstration Site") + +### Have a suggestion, comment or request? + +Please leave a detailed message on the support tab. + +### Let us know what you think + +Please take the time to review the plugin. Your feedback is important and will help us understand the value of this plugin. + +### Disclaimer + +*Gravity Forms is a trademark of Rocketgenius, Inc.* + +*This plugin is provided “as is” without warranty of any kind, expressed or implied. The author shall not be liable for any damages, including but not limited to, direct, indirect, special, incidental or consequential damages or losses that occur out of the use or inability to use the plugin.* + +== Installation == + +### Install and configure the plugin + +1. Install and activate the plugin. +1. Open the ABN Lookup for Gravity forms settings page (Gravity Forms -> Settings -> ABN Lookup menu) and enter your unique GUID (necessary to use the plugin features - provided by the Australian Business Register, see [web services registration](http://abr.business.gov.au/webservices.aspx "Australian Business Register web services registration website")) + +### Create an ABN Lookup field + +1. In your form add or edit a 'Single Line Text' field +1. In the field settings, place a tick next to the 'ABN Lookup field' option + +### To pre-fill GST status from an ABN Lookup field + +1. Add a 'Radio Buttons' field +1. Place a tick next to the 'GST results field' option +1. Using the 'Link ABN Lookup field' drop down select the ABN Lookup field to link to the field to + +== Frequently Asked Questions == + += How do I configure the plugin? = + +A range of options can be found under the Gravity Forms 'ABN Lookup' settings menu. + += How do I use the plugin? = + +1. Install and activate the plugin. +1. Open the ABN Lookup for Gravity forms settings page (Gravity Forms -> Settings -> ABN Lookup menu) and enter your unique GUID (necessary to use the plugin features - provided by the Australian Business Register, see [web services registration](http://abr.business.gov.au/webservices.aspx "Australian Business Register web services registration website")) +1. In your form add or edit a 'Single Line Text' field +1. In the field settings, place a tick next to the 'ABN Lookup field' option + +To pre-fill GST status from an ABN Lookup field: + +1. Add a 'Radio Buttons' field +1. Place a tick next to the 'GST results field' option +1. Using the 'Link ABN Lookup field' drop down select the ABN Lookup field to link to the field to + += How do I change the value attribute of the GST result field? = + +Two filters are available for customising the 'value' attribute for the GST result field: + +itsg_gf_abnlookup_gst_value_yes + +itsg_gf_abnlookup_gst_value_no + +Example usage: + +Please note: there appears to be an issue with returning a '0' value - so in this case return '00'. + +`add_filter( 'itsg_gf_abnlookup_gst_value_yes', 'my_itsg_gf_abnlookup_gst_value_yes', 10, 2 ); + +function my_itsg_gf_abnlookup_gst_value_yes( $text_yes, $form_id ) { + return '10'; +} + +add_filter( 'itsg_gf_abnlookup_gst_value_no', 'my_itsg_gf_abnlookup_gst_value_no', 10, 2 ); + +function my_itsg_gf_abnlookup_gst_value_no( $text_no, $form_id ) { + return '00'; +}` + +== Screenshots == + +1. Shows ABN Lookup field options in the form editor. +1. Shows ABN Lookup field options in the form editor. +1. Shows ABN Lookup field options in the form editor. +1. Shows ABN Lookup for Gravity Forms options page. +1. Shows ABN Lookup field when loading. +1. Shows ABN Lookup field after returning values, complete with pre-filled fields. + +== Changelog == +### 2.0.1 +* TWEAK: Fix JS error when only one business name returned +### 2.0.0 +* ADD: Business Names retrieval on Dropdown field +* DEV: Upgrade to API v202001 +* TWEAK: Improve display of Check ABN button +* TWEAK: Replace indicator graphics +### 1.9.3 +* DEV: Mitigate effect on add-on of `gform_post_conditional_logic` being called by GF core so often +* TEST: Tested WP 6.4 +### 1.9.2 +* DEV: Fix `wp_kses()` error +### 1.9.1 +* Change ownership - BAKKBONE Australia taking on development of this plugin. +* TWEAK: Revert plugin localisation for compatibility. +### 1.9.0 +* DEV: Fix known bug with ABN Lookup tab not displaying in form editor. +* TWEAK: Improve plugin localization. +### 1.8.0 +* Fix: update plugin to be compatible with PHP 8.0 +* Fix: improve compatibility with Gravity Forms 2.5 form editor +* Feature: move field settings to 'ABN Lookup' tab in form editor +### 1.7.0 +* Feature: now uses native WordPress transients to store ABN Lookup cache +* Maintenance: general code review and tidy up +### 1.6.6 +* Fix: resolve "Fatal error: Using $this when not in object context in" when using PHP 5.6 and below. +### 1.6.5 +* Feature: move form admin JavaScript to external file. +* Feature: only show ABN Lookup result options (in form editor) if the form contains an ABN Lookup field. +* Feature: improve handling to minimise someone attempting to make a field BOTH an ABN Lookup field AND result field. +### 1.6.4 +* Feature: better handling when an ABN lookup field hasn't been selected for an ABN result field in the form settings. +### 1.6.3 +* Maintenance: add keyup() event to radio fields when GST yes/no result cleared. For example, when an existing ABN has been entered and later removed. +### 1.6.2 +* Maintenance: add keyup() event to radio fields when GST yes/no result has been updated. Makes it easier to build conditional logic and build number field calculations based on GST status (e.g. GST rate). +### 1.6.1 +* Feature: add options to control ABN Lookup timeout and number of retries before lookup fails. Default remains 5 seconds before timeout and 3 retries. +### 1.6.0 +* Feature: change field validation so that ABN Lookup fields can be set as mandatory (or not), separate from the ABN validation options (registered for GST, is valid etc) +* Maintenance: change how plugin checks for Gravity Forms being installed and active +* Maintenance: add additional sanitisation for ABNs provided by users and passed to the ABR system +### 1.5.0 +* Feature: Add filter to allow custom radio field input values for GST result fields +* Maintenance: improve support for 'List Field Number Format for Gravity Forms' plugin +### 1.4.3 +* Fix: Improve JavaScript error handling in form editor. +### 1.4.1 +* Fix: Patch to allow scripts to enqueue when loading Gravity Form through wp-admin. Gravity Forms 2.0.3.5 currently has a limitation that stops the required scripts from loading through the addon framework. +* Maintenance: Add minified JavaScript and CSS +* Maintenance: Confirm working with WordPress 4.6.0 RC1 +* Maintenance: Update to improve support for Gravity Flow plugin +### 1.4.0 +* Feature: Add 'None' option for ABN Lookup validation. This will allow forms to submit with an invalid ABN, for example if an ABN was recently created and not yet available in the Australian Business Register. +* Feature: Add ABN Registered and GST Registered results options, these can be found in a Date field in the form editor. The date format can be controlled using the standard format option as well as apply conditional logic to the results. +* Fix: Resolve JavaScript 'undefined variable' error message seen in Internet Explorer 11. +* Maintenance: Improve translation support. +### 1.3.2 +* Maintenance: Add some styling to the options in the form editor. +* Maintenance: Moved JavaScript to external file. +* Maintenance: Change JavaScript and CSS to load using Gravity Forms addon framework. +* Maintenance: Tested against Gravity Forms 2.0 RC1. +* Maintenance: Tested against Gravity PDF 4.0 RC4. +### 1.3.1 +* Maintenance: Improve support for PHP version 5.2 and 5.3. +* Maintenance: Improve support for multi-site WordPress installations. +### 1.3.0 +* Feature: Added 'Check ABN' button displayed next to ABN Lookup enabled field. Can be used by user to trigger ABN Lookup and will also make them aware that the form field is special. +* Maintenance: Tweaking CSS. +* Maintenance: Improve do_abnlookup function to stop lookups happening when an ABN Lookup field is empty. +### 1.2.4 +* Maintenance: Improved JavaScript to trigger ABN Lookup when ABN Lookup results field is empty but the linked ABN Lookup field has an ABN. +* Maintenance: Improved translation support. +* Maintenance: Tidy up of PHP code, working towards WordPress standards. +### 1.2.3 +* Fix: Resolve issue with ABN status information appearing in Gravity Forms entry editor. +### 1.2.2 +* Maintenance: Improved handling for when ABN Lookup fields are in a section that has conditional logic applied. +### 1.2.1 +* Fix: Resolve issue with GST field settings not saving in form editor. +### 1.2.0 +* Feature: Change communication method to the Australian Business Register from SOAP to GET. +* Maintenance: Add error handling if an individual entity does not have a middle name. +### 1.1.1 +* Maintenance: Add check for SOAP client to ensure plugin does not cause the 'white screen of death' is web host does not have SOAP installed and enabled. +### 1.1.0 +* Feature: Allow ABN Lookup to be triggered by pressing the enter key. If a user presses the enter key inside an ABN Lookup field the default action of submitting the form will be prevented and the ABN Lookup will begin instead. +* Feature: Add timeout, retry and error message. If unable to communicate with Australian Business register after five seconds the script will try again up to three times. After three times an error message is displayed to the user. +* Maintenance: Refine default messages - invalid message now has a link to the Australian Business Register. +* Maintenance: Make error message styling more consistent with Gravity Forms field error messages. +### 1.0.2 +* FEATURE: Override ABR error message 'Search text is not a valid ABN or ACN' as it is not particularly useful for the end user. If this error message is returned by the ABN Lookup API the 'ABN not valid' error message will be displayed instead. This can be customised in the ABN Lookup for Gravity Forms settings page. +### 1.0.1 +* FIX: Revise JavaScript to resolve issue with linked fields displaying when ABN is not valid. +* FIX: Revise JavaScript to trigger change event when linked fields are pre-filled. This allows Gravity Forms conditional logic to be used against the linked fields. +### 1.0.0 +* First public release. + +== Upgrade Notice == +### 2.0.0 +Upgrades to 2020 API and adds Business Names feature +### 1.9.0 +Fixes major display issue in form editor. \ No newline at end of file diff --git a/trunk/abn-lookup-for-gravity-forms.php b/trunk/abn-lookup-for-gravity-forms.php index 3cd7c0e..2e578a8 100644 --- a/trunk/abn-lookup-for-gravity-forms.php +++ b/trunk/abn-lookup-for-gravity-forms.php @@ -3,7 +3,7 @@ * Plugin Name: ABN Lookup for Gravity Forms * Plugin URI: https://plugins.bkbn.au/docs/abr/ * Description: Connect the Australian Government ABN Lookup tool to Gravity Forms. - * Version: 2.0.0 + * Version: 2.0.1 * Requires at least: 6.0 * Requires PHP: 7.4 * Tested up to: 6.4 diff --git a/trunk/js/abnlookup-script.js b/trunk/js/abnlookup-script.js index f716151..aa1f82b 100644 --- a/trunk/js/abnlookup-script.js +++ b/trunk/js/abnlookup-script.js @@ -1,3 +1,5 @@ + +text/x-generic abnlookup-script.js ( ASCII text ) function itsg_gf_abnlookup_function( field_id, field_validate_abnlookup, field_dateFormat ){ var ajax_url = gf_abnlookup_settings.ajax_url; var validation_message_loading = gf_abnlookup_settings.validation_message_loading; @@ -143,13 +145,19 @@ function itsg_gf_abnlookup_function( field_id, field_validate_abnlookup, field_d } if (typeof businessNames !== 'undefined') { + console.log(businessNames); jQuery('.gform_abnlookup_business_name_field_' + field_id + ' option').remove(); var entityNameOption = new Option(entityName, entityName, true, true); gform_abnlookup_business_name_select.append(entityNameOption); - businessNames.forEach(function(item, index, arr) { - var thisNameOption = new Option(item['organisationName'], item['organisationName'], false, false); - gform_abnlookup_business_name_select.append(thisNameOption); - }); + if (businessNames.length) { + businessNames.forEach(function(item, index, arr) { + var thisNameOption = new Option(item['organisationName'], item['organisationName'], false, false); + gform_abnlookup_business_name_select.append(thisNameOption); + }); + } else { + var thisNameOption = new Option(businessNames['organisationName'], businessNames['organisationName'], false, false); + gform_abnlookup_business_name_select.append(thisNameOption); + } } else { jQuery('.gform_abnlookup_business_name_field_' + field_id + ' option').remove(); var entityNameOption = new Option(entityName, entityName, true, true); diff --git a/trunk/js/abnlookup-script.min.js b/trunk/js/abnlookup-script.min.js index a9f11ce..8ac4a51 100644 --- a/trunk/js/abnlookup-script.min.js +++ b/trunk/js/abnlookup-script.min.js @@ -1 +1 @@ -function itsg_gf_abnlookup_function(e,i,a){var s=gf_abnlookup_settings.ajax_url,o=gf_abnlookup_settings.validation_message_loading,n=gf_abnlookup_settings.validation_message_not_valid,t=gf_abnlookup_settings.validation_message_error_communicating,l=gf_abnlookup_settings.validation_message_11_char,r=gf_abnlookup_settings.text_checking,_=gf_abnlookup_settings.text_check_abn,d=gf_abnlookup_settings.gst_value_yes,p=gf_abnlookup_settings.gst_value_no,u=gf_abnlookup_settings.lookup_timeout,g=gf_abnlookup_settings.lookup_retries;!function(i){"use strict";var a=!1,y=jQuery(".gform_abnlookup_field_"+e+' input[type="text"]'),c=jQuery(".gform_abnlookup_field_"+e+" .gfield_description.validation_message"),f=jQuery(".itsg_abnlookup_response_"+e),h=jQuery(".itsg_abnlookup_checkabn_"+e),v=jQuery(".gform_abnlookup_entity_gst_field_"+e),m=jQuery(".gform_abnlookup_entity_gst_field_"+e+' input[value="'+d+'"]'),b=jQuery(".gform_abnlookup_entity_gst_field_"+e+' input[value="'+p+'"]'),k=jQuery(".gform_abnlookup_entity_type_field_"+e),j=jQuery(".gform_abnlookup_entity_type_field_"+e+" input"),C=jQuery(".gform_abnlookup_entity_status_field_"+e),Q=jQuery(".gform_abnlookup_entity_status_field_"+e+" input"),x=jQuery(".gform_abnlookup_entity_name_field_"+e),N=jQuery(".gform_abnlookup_entity_name_field_"+e+" input"),E=jQuery(".gform_abnlookup_entity_postcode_field_"+e),w=jQuery(".gform_abnlookup_entity_postcode_field_"+e+" input"),A=jQuery(".gform_abnlookup_entity_state_field_"+e),S=jQuery(".gform_abnlookup_entity_state_field_"+e+" input"),D=jQuery(".gform_abnlookup_entity_effective_from_field_"+e),T=jQuery(".gform_abnlookup_entity_effective_from_field_"+e+" input"),F=jQuery(".gform_abnlookup_gst_effective_from_field_"+e),O=jQuery(".gform_abnlookup_gst_effective_from_field_"+e+" input"),B=jQuery(".gform_abnlookup_business_name_field_"+e),P=jQuery(".gform_abnlookup_business_name_field_"+e+" select");jQuery(".gform_abnlookup_business_name_field_"+e+" option");""!==f.html()?((m.is(":visible")&&1!=m.prop("checked")&&1!=b.prop("checked")||j.is(":visible")&&""==j.val()||Q.is(":visible")&&""==Q.val()||N.is(":visible")&&""==N.val()||w.is(":visible")&&""==w.val()||S.is(":visible")&&""==S.val()||T.is(":visible")&&""==T.val()||P.is(":visible")&&""==P.val()||O.is(":visible")&&""==O.val())&&y.trigger("change"),m.is(":checked")?b.prop("disabled",!0):b.is(":checked")&&m.prop("disabled",!0),j.prop("readonly",!0),Q.prop("readonly",!0),N.prop("readonly",!0),w.prop("readonly",!0),S.prop("readonly",!0),T.prop("readonly",!0),O.prop("readonly",!0)):(v.closest("li.gfield").hide(),k.closest("li.gfield").hide(),C.closest("li.gfield").hide(),x.closest("li.gfield").hide(),E.closest("li.gfield").hide(),A.closest("li.gfield").hide(),D.closest("li.gfield").hide(),F.closest("li.gfield").hide(),B.closest("li.gfield").hide()),y.unbind("change").change((function(){var d=jQuery(this).val().replace(/\D/g,"");if(11==d.length){var p={action:"itsg_gf_abnlookup_check_ajax",abn:d};a&&4!==a.readyState&&a.abort(),a=function(a){return i.ajax({type:"POST",url:s,data:a,tryCount:0,retryLimit:g,beforeSend:function(){c.hide(),f.html(o),h.val(r+" ... "),f.addClass("loading"),f.removeClass("error Active Cancelled validation_message")},success:function(i){if(void 0!==i)try{h.val(_);var a=JSON.parse(i);if(null!=a.exception)c.hide(),"Search text is not a valid ABN or ACN"==a.exception.exceptionDescription?f.html(n):f.text(a.exception.exceptionDescription),f.removeClass("Active Cancelled loading"),f.addClass("error validation_message"),v.hide(),k.hide(),C.hide(),x.hide(),E.hide(),A.hide(),D.hide(),F.hide(),B.hide(),j.val("").change(),Q.val("").change(),N.val("").change(),w.val("").change(),S.val("").change(),T.val("").change(),O.val("").change(),jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),m.prop("disabled",!1),b.prop("disabled",!1),m.prop("checked",!1).change().keyup(),b.prop("checked",!1).change().keyup(),j.prop("readonly",!1),Q.prop("readonly",!1),N.prop("readonly",!1),w.prop("readonly",!1),S.prop("readonly",!1),T.prop("readonly",!1),O.prop("readonly",!1);else if(null!=a.businessEntity202001){var s=a.businessEntity202001.entityType.entityTypeCode,o=a.businessEntity202001.entityType.entityDescription,t=a.businessEntity202001.entityStatus.entityStatusCode,l=a.businessEntity202001.mainBusinessPhysicalAddress.postcode,r=a.businessEntity202001.mainBusinessPhysicalAddress.stateCode,d=a.businessEntity202001.entityStatus.effectiveFrom,p=a.businessEntity202001.businessName,u=("0"+(L=new Date(d)).getDate()).slice(-2),g=("0"+(L.getMonth()+1)).slice(-2),y=L.getFullYear();if(T.hasClass("dmy"))var G=u+"/"+g+"/"+y;else G=T.hasClass("dmy_dash")?u+"-"+g+"-"+y:T.hasClass("dmy_dot")?u+"."+g+"."+y:T.hasClass("ymd_slash")?y+"/"+g+"/"+L:T.hasClass("ymd_dash")?y+"-"+g+"-"+L:T.hasClass("ymd_dot")?y+"."+g+"."+L:g+"/"+u+"/"+y;if(null!=a.businessEntity202001.goodsAndServicesTax){var L,M=a.businessEntity202001.goodsAndServicesTax.effectiveFrom;if(u=("0"+(L=new Date(M)).getDate()).slice(-2),g=("0"+(L.getMonth()+1)).slice(-2),y=L.getFullYear(),T.hasClass("dmy"))var Y=u+"/"+g+"/"+y;else Y=O.hasClass("dmy_dash")?u+"-"+g+"-"+y:O.hasClass("dmy_dot")?u+"."+g+"."+y:O.hasClass("ymd_slash")?y+"/"+g+"/"+L:O.hasClass("ymd_dash")?y+"-"+g+"-"+L:O.hasClass("ymd_dot")?y+"."+g+"."+L:g+"/"+u+"/"+y;O.val(Y).change(),O.prop("readonly",!0),F.show()}else F.hide(),O.val("").change();if("IND"==s)var I=("string"==typeof a.businessEntity202001.legalName.familyName?a.businessEntity202001.legalName.familyName:"")+", "+("string"==typeof a.businessEntity202001.legalName.givenName?a.businessEntity202001.legalName.givenName:"")+" "+("string"==typeof a.businessEntity202001.legalName.otherGivenName?a.businessEntity202001.legalName.otherGivenName:"");else I=a.businessEntity202001.mainName.organisationName;if(void 0!==p){jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove();var J=new Option(I,I,!0,!0);P.append(J),p.forEach((function(e,i,a){var s=new Option(e.organisationName,e.organisationName,!1,!1);P.append(s)}))}else jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),J=new Option(I,I,!0,!0),P.append(J);c.hide(),f.text(t+" - "+I),j.val(o).change(),j.prop("readonly",!0),Q.val(t).change(),Q.prop("readonly",!0),N.val(I).change(),N.prop("readonly",!0),w.val(l).change(),w.prop("readonly",!0),S.val(r).change(),S.prop("readonly",!0),T.val(G).change(),T.prop("readonly",!0),f.removeClass("error loading validation_message"),f.addClass(t),null!=a.businessEntity202001.goodsAndServicesTax&&"0001-01-01"==a.businessEntity202001.goodsAndServicesTax.effectiveTo?(m.prop("checked",!0).click().change().keyup(),m.prop("disabled",!1),b.prop("disabled",!0)):(b.prop("checked",!0).click().change().keyup(),b.prop("disabled",!1),m.prop("disabled",!0)),v.show(),k.show(),x.show(),C.show(),E.show(),A.show(),D.show(),B.show()}}catch(e){f.text(e),f.removeClass("loading Active Cancelled"),f.addClass("error validation_message")}},error:function(e,a,s){if("timeout"==a){if(this.tryCount++,this.tryCount<=this.retryLimit)return void i.ajax(this);f.text(t)}else f.text(e.responseText);h.val(_),f.removeClass("loading Active Cancelled"),f.addClass("error validation_message")},timeout:u})}(p)}else v.hide(),k.hide(),C.hide(),x.hide(),E.hide(),A.hide(),D.hide(),F.hide(),B.hide(),j.val("").change(),Q.val("").change(),N.val("").change(),w.val("").change(),S.val("").change(),T.val("").change(),jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),O.val("").change(),m.prop("disabled",!1),b.prop("disabled",!1),m.prop("checked",!1).change().keyup(),b.prop("checked",!1).change().keyup(),c.hide(),f.html(l),f.addClass("error validation_message"),f.removeClass("loading Active Cancelled")}))}(jQuery)}jQuery(document).ready((function(e){var i=gf_abnlookup_settings.abnlookup_fields,a=gf_abnlookup_settings.form_id;for(var s in i){var o=s;jQuery("#input_"+a+"_"+o).unbind("keydown").keydown((function(e){13!=e.which&&13!=e.keyCode||(e.preventDefault(),jQuery(this).trigger("change"))})),jQuery("#input_"+a+"_"+o).unbind("keyup").keyup((function(e){13!=e.which&&13!=e.keyCode||e.preventDefault()})),jQuery("#input_"+a+"_"+o).on("change keyup",(function(e){var a=i[s].validate,n=i[s].dateFormat;void 0!==a&&itsg_gf_abnlookup_function(o,a,n)}))}})); \ No newline at end of file +function itsg_gf_abnlookup_function(e,i,a){var o=gf_abnlookup_settings.ajax_url,n=gf_abnlookup_settings.validation_message_loading,s=gf_abnlookup_settings.validation_message_not_valid,t=gf_abnlookup_settings.validation_message_error_communicating,l=gf_abnlookup_settings.validation_message_11_char,r=gf_abnlookup_settings.text_checking,d=gf_abnlookup_settings.text_check_abn,_=gf_abnlookup_settings.gst_value_yes,p=gf_abnlookup_settings.gst_value_no,u=gf_abnlookup_settings.lookup_timeout,g=gf_abnlookup_settings.lookup_retries;!function(i){"use strict";var a=!1,y=jQuery(".gform_abnlookup_field_"+e+' input[type="text"]'),c=jQuery(".gform_abnlookup_field_"+e+" .gfield_description.validation_message"),f=jQuery(".itsg_abnlookup_response_"+e),h=jQuery(".itsg_abnlookup_checkabn_"+e),v=jQuery(".gform_abnlookup_entity_gst_field_"+e),m=jQuery(".gform_abnlookup_entity_gst_field_"+e+' input[value="'+_+'"]'),b=jQuery(".gform_abnlookup_entity_gst_field_"+e+' input[value="'+p+'"]'),k=jQuery(".gform_abnlookup_entity_type_field_"+e),j=jQuery(".gform_abnlookup_entity_type_field_"+e+" input"),C=jQuery(".gform_abnlookup_entity_status_field_"+e),Q=jQuery(".gform_abnlookup_entity_status_field_"+e+" input"),x=jQuery(".gform_abnlookup_entity_name_field_"+e),N=jQuery(".gform_abnlookup_entity_name_field_"+e+" input"),E=jQuery(".gform_abnlookup_entity_postcode_field_"+e),w=jQuery(".gform_abnlookup_entity_postcode_field_"+e+" input"),A=jQuery(".gform_abnlookup_entity_state_field_"+e),S=jQuery(".gform_abnlookup_entity_state_field_"+e+" input"),D=jQuery(".gform_abnlookup_entity_effective_from_field_"+e),T=jQuery(".gform_abnlookup_entity_effective_from_field_"+e+" input"),O=jQuery(".gform_abnlookup_gst_effective_from_field_"+e),F=jQuery(".gform_abnlookup_gst_effective_from_field_"+e+" input"),B=jQuery(".gform_abnlookup_business_name_field_"+e),P=jQuery(".gform_abnlookup_business_name_field_"+e+" select");jQuery(".gform_abnlookup_business_name_field_"+e+" option");""!==f.html()?((m.is(":visible")&&1!=m.prop("checked")&&1!=b.prop("checked")||j.is(":visible")&&""==j.val()||Q.is(":visible")&&""==Q.val()||N.is(":visible")&&""==N.val()||w.is(":visible")&&""==w.val()||S.is(":visible")&&""==S.val()||T.is(":visible")&&""==T.val()||P.is(":visible")&&""==P.val()||F.is(":visible")&&""==F.val())&&y.trigger("change"),m.is(":checked")?b.prop("disabled",!0):b.is(":checked")&&m.prop("disabled",!0),j.prop("readonly",!0),Q.prop("readonly",!0),N.prop("readonly",!0),w.prop("readonly",!0),S.prop("readonly",!0),T.prop("readonly",!0),F.prop("readonly",!0)):(v.closest("li.gfield").hide(),k.closest("li.gfield").hide(),C.closest("li.gfield").hide(),x.closest("li.gfield").hide(),E.closest("li.gfield").hide(),A.closest("li.gfield").hide(),D.closest("li.gfield").hide(),O.closest("li.gfield").hide(),B.closest("li.gfield").hide()),y.unbind("change").change((function(){var _=jQuery(this).val().replace(/\D/g,"");if(11==_.length){var p={action:"itsg_gf_abnlookup_check_ajax",abn:_};a&&4!==a.readyState&&a.abort(),a=function(a){return i.ajax({type:"POST",url:o,data:a,tryCount:0,retryLimit:g,beforeSend:function(){c.hide(),f.html(n),h.val(r+" ... "),f.addClass("loading"),f.removeClass("error Active Cancelled validation_message")},success:function(i){if(void 0!==i)try{h.val(d);var a=JSON.parse(i);if(null!=a.exception)c.hide(),"Search text is not a valid ABN or ACN"==a.exception.exceptionDescription?f.html(s):f.text(a.exception.exceptionDescription),f.removeClass("Active Cancelled loading"),f.addClass("error validation_message"),v.hide(),k.hide(),C.hide(),x.hide(),E.hide(),A.hide(),D.hide(),O.hide(),B.hide(),j.val("").change(),Q.val("").change(),N.val("").change(),w.val("").change(),S.val("").change(),T.val("").change(),F.val("").change(),jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),m.prop("disabled",!1),b.prop("disabled",!1),m.prop("checked",!1).change().keyup(),b.prop("checked",!1).change().keyup(),j.prop("readonly",!1),Q.prop("readonly",!1),N.prop("readonly",!1),w.prop("readonly",!1),S.prop("readonly",!1),T.prop("readonly",!1),F.prop("readonly",!1);else if(null!=a.businessEntity202001){var o=a.businessEntity202001.entityType.entityTypeCode,n=a.businessEntity202001.entityType.entityDescription,t=a.businessEntity202001.entityStatus.entityStatusCode,l=a.businessEntity202001.mainBusinessPhysicalAddress.postcode,r=a.businessEntity202001.mainBusinessPhysicalAddress.stateCode,_=a.businessEntity202001.entityStatus.effectiveFrom,p=a.businessEntity202001.businessName,u=("0"+(L=new Date(_)).getDate()).slice(-2),g=("0"+(L.getMonth()+1)).slice(-2),y=L.getFullYear();if(T.hasClass("dmy"))var G=u+"/"+g+"/"+y;else G=T.hasClass("dmy_dash")?u+"-"+g+"-"+y:T.hasClass("dmy_dot")?u+"."+g+"."+y:T.hasClass("ymd_slash")?y+"/"+g+"/"+L:T.hasClass("ymd_dash")?y+"-"+g+"-"+L:T.hasClass("ymd_dot")?y+"."+g+"."+L:g+"/"+u+"/"+y;if(null!=a.businessEntity202001.goodsAndServicesTax){var L,M=a.businessEntity202001.goodsAndServicesTax.effectiveFrom;if(u=("0"+(L=new Date(M)).getDate()).slice(-2),g=("0"+(L.getMonth()+1)).slice(-2),y=L.getFullYear(),T.hasClass("dmy"))var Y=u+"/"+g+"/"+y;else Y=F.hasClass("dmy_dash")?u+"-"+g+"-"+y:F.hasClass("dmy_dot")?u+"."+g+"."+y:F.hasClass("ymd_slash")?y+"/"+g+"/"+L:F.hasClass("ymd_dash")?y+"-"+g+"-"+L:F.hasClass("ymd_dot")?y+"."+g+"."+L:g+"/"+u+"/"+y;F.val(Y).change(),F.prop("readonly",!0),O.show()}else O.hide(),F.val("").change();if("IND"==o)var I=("string"==typeof a.businessEntity202001.legalName.familyName?a.businessEntity202001.legalName.familyName:"")+", "+("string"==typeof a.businessEntity202001.legalName.givenName?a.businessEntity202001.legalName.givenName:"")+" "+("string"==typeof a.businessEntity202001.legalName.otherGivenName?a.businessEntity202001.legalName.otherGivenName:"");else I=a.businessEntity202001.mainName.organisationName;if(void 0!==p){console.log(p),jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove();var J=new Option(I,I,!0,!0);if(P.append(J),p.length)p.forEach((function(e,i,a){var o=new Option(e.organisationName,e.organisationName,!1,!1);P.append(o)}));else{var q=new Option(p.organisationName,p.organisationName,!1,!1);P.append(q)}}else jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),J=new Option(I,I,!0,!0),P.append(J);c.hide(),f.text(t+" - "+I),j.val(n).change(),j.prop("readonly",!0),Q.val(t).change(),Q.prop("readonly",!0),N.val(I).change(),N.prop("readonly",!0),w.val(l).change(),w.prop("readonly",!0),S.val(r).change(),S.prop("readonly",!0),T.val(G).change(),T.prop("readonly",!0),f.removeClass("error loading validation_message"),f.addClass(t),null!=a.businessEntity202001.goodsAndServicesTax&&"0001-01-01"==a.businessEntity202001.goodsAndServicesTax.effectiveTo?(m.prop("checked",!0).click().change().keyup(),m.prop("disabled",!1),b.prop("disabled",!0)):(b.prop("checked",!0).click().change().keyup(),b.prop("disabled",!1),m.prop("disabled",!0)),v.show(),k.show(),x.show(),C.show(),E.show(),A.show(),D.show(),B.show()}}catch(e){f.text(e),f.removeClass("loading Active Cancelled"),f.addClass("error validation_message")}},error:function(e,a,o){if("timeout"==a){if(this.tryCount++,this.tryCount<=this.retryLimit)return void i.ajax(this);f.text(t)}else f.text(e.responseText);h.val(d),f.removeClass("loading Active Cancelled"),f.addClass("error validation_message")},timeout:u})}(p)}else v.hide(),k.hide(),C.hide(),x.hide(),E.hide(),A.hide(),D.hide(),O.hide(),B.hide(),j.val("").change(),Q.val("").change(),N.val("").change(),w.val("").change(),S.val("").change(),T.val("").change(),jQuery(".gform_abnlookup_business_name_field_"+e+" option").remove(),F.val("").change(),m.prop("disabled",!1),b.prop("disabled",!1),m.prop("checked",!1).change().keyup(),b.prop("checked",!1).change().keyup(),c.hide(),f.html(l),f.addClass("error validation_message"),f.removeClass("loading Active Cancelled")}))}(jQuery)}jQuery(document).ready((function(e){var i=gf_abnlookup_settings.abnlookup_fields,a=gf_abnlookup_settings.form_id;for(var o in i){var n=o;jQuery("#input_"+a+"_"+n).unbind("keydown").keydown((function(e){13!=e.which&&13!=e.keyCode||(e.preventDefault(),jQuery(this).trigger("change"))})),jQuery("#input_"+a+"_"+n).unbind("keyup").keyup((function(e){13!=e.which&&13!=e.keyCode||e.preventDefault()})),jQuery("#input_"+a+"_"+n).on("change keyup",(function(e){var a=i[o].validate,s=i[o].dateFormat;void 0!==a&&itsg_gf_abnlookup_function(n,a,s)}))}})); \ No newline at end of file diff --git a/trunk/readme.txt b/trunk/readme.txt index bc25b3c..e474af8 100644 --- a/trunk/readme.txt +++ b/trunk/readme.txt @@ -5,7 +5,7 @@ Tags: gravity forms, forms, ajax, abn, australian business number, australian bu Requires at least: 6.0 Tested up to: 6.4 Requires PHP: 7.4 -Stable tag: 2.0.0 +Stable tag: 2.0.1 License: GNU General Public License (GPL) 3.0 License URI: https://www.gnu.org/licenses/gpl.html @@ -115,6 +115,8 @@ function my_itsg_gf_abnlookup_gst_value_no( $text_no, $form_id ) { 1. Shows ABN Lookup field after returning values, complete with pre-filled fields. == Changelog == +### 2.0.1 +* TWEAK: Fix JS error when only one business name returned ### 2.0.0 * ADD: Business Names retrieval on Dropdown field * DEV: Upgrade to API v202001