简体   繁体   English

SuiteCRM - jQuery蒙面输入插件无法正常工作

[英]SuiteCRM - jQuery Masked Input Plugin Not Working

I have checked several other threads on here related to masked input plugins not working and was unable to find any answers: 我已经检查了几个与屏蔽输入插件无关的其他线程无法找到任何答案:

Masked Input Plugin not working Masked Input Plugin无法正常工作

jQuery Masked Input plugin not working on form input? jQuery Masked Input插件无法处理表单输入?

JQuery Masked Input plugin doesn't work JQuery Masked Input插件不起作用

I should preface this by saying that my programming knowledge is rather limited. 我应该先说明我的编程知识相当有限。 I have help, but that help isn't always available. 我有帮助,但并不总是有这种帮助。

I am attempting to use this plugin 我试图使用这个插件

My Version #: SuiteCRM Version 7.2.1, Sugar Version 6.5.20 (Build 1001) 我的版本号:SuiteCRM版本7.2.1,Sugar版本6.5.20(Build 1001)

So I added the jQuery javascript library file and the jQuery plugin from digitalbrushes website and put them both in /admin/custom/include/javascript/ 所以我从digitalbrushes网站添加了jQuery javascript库文件和jQuery插件,并将它们放在/ admin / custom / include / javascript /中

Then under the module I am currently working on which in this case is the Contracts module, the file I am working on is here: /admin/custom/modules/AOS_Contracts/views/view.edit.php 然后在我正在处理的模块下,在这种情况下是Contracts模块,我正在处理的文件在这里:/admin/custom/modules/AOS_Contracts/views/view.edit.php

Below is the file: 以下是文件:

<?php 
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 

require_once('include/MVC/View/views/view.edit.php'); 

class AOS_ContractsViewEdit extends ViewEdit {

// function displaySubPanels() {
//  return '';
// }

function display(){
    $js = <<<JS

            <script src="/admin/custom/include/javascript/jquery.min.js" type="text/javascript">
            <script src="/admin/custom/include/javascript/jquery.maskedinput.min.js" type="text/javascript">
            var \$j = jQuery.noConflict();
                \$j("#home_phone_c").mask("(999) 999-9999");
                \$j("#work_phone_c").mask("(999) 999-9999");
                \$j("#mobile_phone_c").mask("(999) 999-9999");
                \$j("#inital_deposit_amount_c").mask("999,999,999,999,999.99");
                });
            </script>
    JS;
        parent::display();
        echo $js;

    }

}

When I load the page and click in the fields, there is no masks present, in my chrome console I am only getting an unrelated error in my style.js file that says: 当我加载页面并单击字段时,没有掩码存在,在我的chrome控制台中我只在我的style.js文件中得到一个不相关的错误:

"Uncaught TypeError: $.cookie is not a function" “未捕获的TypeError:$ .cookie不是函数”

I have already tried wrapping this in {literal} tags as suggested by this answer: Adding custom jQuery validation in SugarCRM editview , nothing changed. 我已经尝试将此包装在{literal}标签中,如此答案所示: 在SugarCRM editview中添加自定义jQuery验证 ,没有任何改变。 I'm not really certain how or if the .ready(function() is applied to this if it is necessary. I didn't think it was because of parent::display(); . 我真的不确定.ready(如果有必要的话,函数()是否应用于此。我不认为这是因为parent::display();

I have tried this same page in Chrome, Firefox, Safari, and IE.... nothing. 我在Chrome,Firefox,Safari和IE中尝试了同样的页面....没有。 I also cleared my cache and cookies after I made the changes to ensure I was getting fresh results. 在我做出更改后,我还清除了缓存和cookie,以确保我获得了新的结​​果。 I have also done a quick repair and rebuild on SuiteCRM everytime (although that should be completely unnecessary) just to cover my bases. 我每次都在SuiteCRM上进行了快速修复和重建(虽然这应该是完全没必要的)只是为了覆盖我的基础。

I was able to get help on SuiteCRM's forum. 我能够在SuiteCRM的论坛上获得帮助。

-I needed this cookie plugin - 我需要这个 cookie插件

-In my syntax above src="jquery.maskedinput.min.js" needed to be omitted. - 在我的语法上面src="jquery.maskedinput.min.js"需要省略。

-In my syntax above, \\$j was creating an infinite error in the chrome console that only appeared once the above syntax was removed, I omitted the j and then that cleared it up! - 在上面的语法中, \\$j在chrome控制台中创建了一个无限错误,只有在上面的语法被删除后才会出现,我省略了j然后清除了它!

The corrected code looks like this: 更正后的代码如下所示:

<?php 
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 

require_once('include/MVC/View/views/view.edit.php'); 

class AOS_ContractsViewEdit extends ViewEdit {

    // function displaySubPanels() {
    //  return '';
    // }

    function display(){
        $js = <<<JS

                <script src="custom/include/javascript/js.cookie.js" type="text/javascript"></script>
                <script type="text/javascript">
                var \$ = jQuery.noConflict();
                    \$("#home_phone_c").mask("(999) 999-9999");
                    \$("#work_number_c").mask("(999) 999-9999");
                    \$("#mobile_number_c").mask("(999) 999-9999");
                    \$("#inital_deposit_amount_c").mask("");
                </script>
JS;
        parent::display();
        echo $js;

    }

}
?>

You need to add JS file in metadata using "include". 您需要使用“include”在元数据中添加JS文件。 Then write your code in that file. 然后在该文件中编写代码。 Writing java-script code inside PHP view is not suggested by Sugar. Sugar不建议在PHP视图中编写java脚本代码。

If you only need view.edit for this purpose then at the end this file will not be needed and hence get deleted. 如果您只需要view.edit用于此目的,那么最后将不需要此文件,因此将被删除。 Let me know if you need further details. 如果您需要更多详细信息,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM