Răsfoiți Sursa

Ticket #3684 - JS error in 'Add New...' block when Async mode is enabled.

AntonLV 4 ani în urmă
părinte
comite
8d3a8cab40

+ 1 - 11
template/form_field_custom_suggestions.html

@@ -4,14 +4,4 @@
     </bx_repeat:vals>
     <bx_if:input>__input__</bx_if:input>
 </div>
-<bx_if:init>
-    <script language="javascript">
-        $(function(){
-            $('#__id__ input').on('focus', function () {
-                $(this).attr("placeholder", "__placeholder__");
-            });
-
-            bx_autocomplete_fields('__id__','__url_get_recipients__','__name__',__b_img__,__only_once__,__on_select__);
-        });
-    </script>
-</bx_if:init>
+__js_code__

+ 5 - 0
template/form_field_custom_suggestions_js.html

@@ -0,0 +1,5 @@
+$('#__id__ input').on('focus', function () {
+    $(this).attr("placeholder", "__placeholder__");
+});
+
+bx_autocomplete_fields('__id__','__url_get_recipients__','__name__',__b_img__,__only_once__,__on_select__);

+ 21 - 12
template/scripts/BxBaseFormView.php

@@ -1537,6 +1537,26 @@ BLAH;
 
         $this->addCssJsUi();
 
+        $sJsCode = '';
+        if(!$bDisabled) {
+            $sJsCode = $this->oTemplate->parseHtmlByName('form_field_custom_suggestions_js.html', [
+                'id' => $aAttrs['id'],
+                'name' => $aInput['name'],
+                'url_get_recipients' => $aInput['ajax_get_suggestions'],
+                'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
+                'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
+                'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
+                'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
+            ]);
+
+            if($this->_bDynamicMode)
+                $sJsCode = $this->oTemplate->addJsPreloadedWrapped([
+                    'jquery-ui/jquery-ui.custom.min.js'
+                ], $sJsCode);
+            else 
+                $sJsCode = $this->oTemplate->addJsCodeOnLoadWrapped($sJsCode);
+        }       
+
         return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
             'name' => $aInput['name'],
             'attrs' => bx_convert_array2attrs($aAttrs),
@@ -1545,18 +1565,7 @@ BLAH;
                 'condition' => !$bDisabled,
                 'content' => $aTmplVarsInputText
             ),
-            'bx_if:init' => array(
-                'condition' => !$bDisabled,
-                'content' => array(
-                    'id' => $aAttrs['id'],
-                    'name' => $aInput['name'],
-                    'url_get_recipients' => $aInput['ajax_get_suggestions'],
-                    'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
-                    'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
-                    'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
-                    'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
-                )
-            )
+            'js_code' => $sJsCode
         ));
     }