Author: adityasharma
Date: Sat Mar 30 07:12:36 2019
New Revision: 1856610
URL: http://svn.apache.org/viewvc?rev=1856610&view=rev
Log:
Improved: Replace Inline js with External js in renderDropDownField macro.
(OFBIZ-9849)
Silghtly modified patch as Specify-other Dropdown field were not working.
Refactored code in combobox.js file
Thanks Dhaval Wagela for the initial patch
Modified:
ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js
ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/combobox.js
Modified:
ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl?rev=1856610&r1=1856609&r2=1856610&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
(original)
+++
ofbiz/ofbiz-framework/trunk/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
Sat Mar 30 07:12:36 2019
@@ -140,12 +140,17 @@ under the License.
</span>
</#macro>
-<#macro renderDropDownField name className alert id formName otherFieldName
action explicitDescription options fieldName otherFieldName otherValue
otherFieldSize ajaxEnabled ajaxOptions frequency minChars choices autoSelect
partialSearch partialChars ignoreCase fullSearch conditionGroup="" tabindex=""
multiple="" event="" size="" firstInList="" currentValue="" allowEmpty=""
dDFCurrent="" noCurrentSelectedKey="">
+<#macro renderDropDownField name className alert id formName action
explicitDescription options fieldName otherFieldName otherValue otherFieldSize
ajaxEnabled ajaxOptions frequency minChars choices autoSelect partialSearch
partialChars ignoreCase fullSearch conditionGroup="" tabindex="" multiple=""
event="" size="" firstInList="" currentValue="" allowEmpty="" dDFCurrent=""
noCurrentSelectedKey="">
<#if conditionGroup?has_content>
<input type="hidden" name="${name}_grp" value="${conditionGroup}"/>
</#if>
<span class="ui-widget">
- <select name="${name?default("")}<#rt/>" <@renderClass className alert
/><#if id?has_content> id="${id}"</#if><#if multiple?has_content>
multiple="multiple"</#if><#if otherFieldSize gt 0>
onchange="process_choice(this,document.${formName}.${otherFieldName})"</#if><#if
event?has_content> ${event}="${action}"</#if><#if size?has_content>
size="${size}"</#if><#if tabindex?has_content>
tabindex="${tabindex}"</#if><#rt/>>
+ <select name="${name?default("")}<#rt/>" <@renderClass className alert
/><#if id?has_content> id="${id}"</#if><#if multiple?has_content>
multiple="multiple"</#if><#if ajaxEnabled>
class="autoCompleteDropDown"</#if><#if event?has_content>
${event}="${action}"</#if><#if size?has_content> size="${size}"</#if><#if
tabindex?has_content> tabindex="${tabindex}"</#if><#rt/>
+ <#if otherFieldName?has_content>
+ data-other-field-name="${otherFieldName}"
+ data-other-field-value='${otherValue?js_string}'
+ data-other-field-size='${otherFieldSize}'
+ </#if>>
<#if firstInList?has_content && currentValue?has_content &&
!multiple?has_content>
<option selected="selected"
value="${currentValue}">${explicitDescription?replace("\'","'")}</option><#rt/><#--
replace("\'","'") related to OFBIZ-6504 -->
</#if>
@@ -165,23 +170,6 @@ under the License.
</span>
<#if otherFieldName?has_content>
<noscript><input type='text' name='${otherFieldName}' /></noscript>
- <script type='application/javascript'><!--
- disa = ' disabled';
- if(other_choice(document.${formName}.${fieldName}))
- disa = '';
- document.write("<input type='text' name='${otherFieldName}'
value='${otherValue?js_string}' size='${otherFieldSize}'"+disa+"
onfocus='check_choice(document.${formName}.${fieldName})' />");
- if(disa && document.styleSheets)
- document.${formName}.${otherFieldName}.style.visibility = 'hidden';
- //--></script>
- </#if>
-
- <#if ajaxEnabled>
- <script type="application/javascript">
- ajaxAutoCompleteDropDown();
- jQuery(function() {
- jQuery("#${id}").combobox();
- });
- </script>
</#if>
</#macro>
Modified:
ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js?rev=1856610&r1=1856609&r2=1856610&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js
(original)
+++
ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js
Sat Mar 30 07:12:36 2019
@@ -25,6 +25,8 @@ var AJAX_REQUEST_TIMEOUT = 5000;
// Add observers on DOM ready.
$(document).ready(function() {
+ //initializing UI combobox dropdown by overriding its methods.
+ ajaxAutoCompleteDropDown();
// bindObservers will add observer on passed html section when DOM is
ready.
bindObservers("body");
});
@@ -63,6 +65,30 @@ function bindObservers(bind_element) {
var mask = element.data('mask');
element.mask(mask);
});
+ jQuery(bind_element).find('.autoCompleteDropDown').each(function(){
+ jQuery(this).combobox();
+ });
+ jQuery(bind_element).find('[data-other-field-name]').each(function(){
+ var element = jQuery(this);
+ var otherFieldName = element.data("other-field-name");
+ var otherFieldValue = element.data("other-field-value");
+ var otherFieldSize = element.data("other-field-size");
+ var disabled = true;
+ if(other_choice(this))
+ disabled = false;
+ var $input = jQuery("<input>", {type: "text", name: otherFieldName})
+ .attr("size", otherFieldSize)
+ .val(otherFieldValue)
+ .on("focus", function(e){
+ check_choice(element);
+ })
+ .css('visibility', 'hidden');
+ $input.prop("disabled", disabled);
+ $input.insertAfter(element.closest(".ui-widget"));
+ element.on("change", function(e) {
+ process_choice(element[0], $input);
+ })
+ });
jQuery(bind_element).find(".visual-editor").each(function(){
var element = jQuery(this);
var toolbar = element.data('toolbar');
@@ -830,6 +856,13 @@ function ajaxAutoCompleteDropDown() {
});
},
change: function( event, ui ) {
+ var element = jQuery(this);
+ if (element.data('other-field-name') != undefined) {
+ var otherField =
(element.form()).find("input[name=" + element.data('other-field-name') + "]");
+ if (otherField != undefined) {
+ process_choice(element, jQuery(otherField));
+ }
+ }
if ( !ui.item ) {
var matcher = new RegExp( "^" +
jQuery.ui.autocomplete.escapeRegex( jQuery(this).val() ) + "$", "i" ),
valid = false;
Modified:
ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/combobox.js
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/combobox.js?rev=1856610&r1=1856609&r2=1856610&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/combobox.js
(original)
+++
ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/combobox.js
Sat Mar 30 07:12:36 2019
@@ -18,26 +18,21 @@
*/
function other_choice(dropDown) {
- opt = dropDown.options[dropDown.selectedIndex];
- ret = false;
- if (opt.value == "_OTHER_") ret = true;
- return ret;
+ var optValue = jQuery(dropDown).children("option:selected").val();
+ return optValue == "_OTHER_";
}
function activate(field) {
- field.disabled=false;
- if(document.styleSheets)field.style.visibility = 'visible';
- field.focus();
+ field.prop("disabled",false)
+ .css('visibility', 'visible')
+ .focus();
}
function process_choice(selection,textfield) {
- b = other_choice(selection);
- if(b) {
- activate(textfield); }
- else {
- textfield.disabled = true;
- if(document.styleSheets)textfield.style.visibility = 'hidden';
- textfield.value = '';
+ if(other_choice(selection)) {
+ activate(textfield);
+ } else {
+ textfield.prop("disabled", true).val('').css('visibility', 'hidden');
}
}