为什么 JQueryUI 不适用于 salesforce 标准输入元素?

发布于 2024-12-09 05:00:06 字数 490 浏览 0 评论 0原文

我在将 JQueryUI 与 salesforce 标准元素一起使用时遇到问题。基本上,我想自动向用户建议记录名称,而不是用户单击 salesforce 搜索按钮。

<apex:inputField value="{!MyRecord.ChildRecord__c}" id="inpId" required="true/>

<script>
   jq$(document.getElementById('{!$Component.inpId}')).autocomplete( { 
            minLength: 2,
            autoFocus: true,
            source: mySource
   });
</script>

因此,我想知道是否有人尝试将 JQueryUI 与标准 salesforce 输入元素一起使用。就我而言,JQueryUI 事件不会针对 salesforce 元素触发。

I am having trouble using JQueryUI with salesforce standard elements. Basically, I want to auto suggest the record names to the user, instead of the user clicking on the salesforce search button.

<apex:inputField value="{!MyRecord.ChildRecord__c}" id="inpId" required="true/>

<script>
   jq$(document.getElementById('{!$Component.inpId}')).autocomplete( { 
            minLength: 2,
            autoFocus: true,
            source: mySource
   });
</script>

Therefore, I want to know if anyone attempted to use JQueryUI with standard salesforce input elements. In my case, the JQueryUI events are not firing for salesforce elements.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强者自强 2024-12-16 05:00:06

{!$Component.[elementid]} 并不总是适合我;我不知道为什么。我更喜欢使用属性结尾选择器(http://api.jquery.com/属性结尾带有选择器/)。

尝试这样的事情:

<apex:includeScript value="/soap/ajax/18.0/connection.js" />
<apex:includeScript value="/soap/ajax/18.0/apex.js" />

<script>
    var j$ = jQuery.noConflict();
    j$(document).ready(function(){init();});

    function init()
    {
        var mySourceText = "ActionScript AppleScript Asp BASIC C "
           + "C++ Clojure COBOL ColdFusion Erlang Fortran Groovy "
           + "Haskell Java JavaScript Lisp Perl PHP Python Ruby "
           + "Scala Scheme";

        var mySource = mySourceText.split(" ");

        j$("[id$='myInput']").autocomplete({ 
            minLength: 2,
            autoFocus: true,
            source: function(request, response){ 
                    response(GetSourceAjaxAPI(request.term)); }
        });
    }

    function GetSourceAjaxAPI(s)
    {
        var result = sforce.apex.execute("TestAutocomplete", 
                     "GetAutocompleteValuesAjaxAPI", {SearchTerm:s});
        return result;
    }
</script>

<apex:form >
    <apex:pageblock >
        <apex:pageblocksection >
            <apex:pageblocksectionitem >
                <apex:inputfield id="myInput" value="{!Contact.FirstName}" />
            </apex:pageblocksectionitem>
        </apex:pageblocksection>
    </apex:pageblock>
</apex:form>

控制器:

global class TestAutocomplete 
{
    global TestAutocomplete(ApexPages.StandardController myStandardController) {}

    webservice static List<String> 
        GetAutocompleteValuesAjaxAPI(String SearchTerm)
    {            
        String mySourceText = 'ActionScript AppleScript Asp BASIC C '
           + 'C++ Clojure COBOL ColdFusion Erlang Fortran Groovy '
           + 'Haskell Java JavaScript Lisp Perl PHP Python Ruby '
           + 'Scala Scheme';

        List<String> mySourceList = mySourceText.split(' ');
        List<String> myReturnList = new List<String>();

        for(String s : mySourceList)
        {
            if(s.contains(SearchTerm)){ myReturnList.add(s); }
        }

        return myReturnList;
    }
}

希望有帮助,
马特

{!$Component.[elementid]} doesn't always work for me; I'm not sure why. I prefer to use the Attribute Ends With Selector (http://api.jquery.com/attribute-ends-with-selector/).

Try something like this:

<apex:includeScript value="/soap/ajax/18.0/connection.js" />
<apex:includeScript value="/soap/ajax/18.0/apex.js" />

<script>
    var j$ = jQuery.noConflict();
    j$(document).ready(function(){init();});

    function init()
    {
        var mySourceText = "ActionScript AppleScript Asp BASIC C "
           + "C++ Clojure COBOL ColdFusion Erlang Fortran Groovy "
           + "Haskell Java JavaScript Lisp Perl PHP Python Ruby "
           + "Scala Scheme";

        var mySource = mySourceText.split(" ");

        j$("[id$='myInput']").autocomplete({ 
            minLength: 2,
            autoFocus: true,
            source: function(request, response){ 
                    response(GetSourceAjaxAPI(request.term)); }
        });
    }

    function GetSourceAjaxAPI(s)
    {
        var result = sforce.apex.execute("TestAutocomplete", 
                     "GetAutocompleteValuesAjaxAPI", {SearchTerm:s});
        return result;
    }
</script>

<apex:form >
    <apex:pageblock >
        <apex:pageblocksection >
            <apex:pageblocksectionitem >
                <apex:inputfield id="myInput" value="{!Contact.FirstName}" />
            </apex:pageblocksectionitem>
        </apex:pageblocksection>
    </apex:pageblock>
</apex:form>

Controller:

global class TestAutocomplete 
{
    global TestAutocomplete(ApexPages.StandardController myStandardController) {}

    webservice static List<String> 
        GetAutocompleteValuesAjaxAPI(String SearchTerm)
    {            
        String mySourceText = 'ActionScript AppleScript Asp BASIC C '
           + 'C++ Clojure COBOL ColdFusion Erlang Fortran Groovy '
           + 'Haskell Java JavaScript Lisp Perl PHP Python Ruby '
           + 'Scala Scheme';

        List<String> mySourceList = mySourceText.split(' ');
        List<String> myReturnList = new List<String>();

        for(String s : mySourceList)
        {
            if(s.contains(SearchTerm)){ myReturnList.add(s); }
        }

        return myReturnList;
    }
}

Hope that helps,
Matt

南风起 2024-12-16 05:00:06

我找出了 JQeuryUI 无法在 SalesForce 标准输入元素上工作的原因。我试图在输入元素上使用 JQueryUI 自动完成功能。应该调用的操作函数没有被调用,因为我没有

<apex:actionFunction immediate="true" />

设置立即= true属性,以便立即调用操作函数。如果我们没有设置此属性,SalesForce 会尝试验证所有标准输入元素,如果验证失败,则永远不会调用操作函数。

I figured out the reason why JQeuryUI was not working on SalesForce standard input element. I was trying to use JQueryUI autocomplete on the input element. The action function that was supposed to be invoked was not called because I did not have

<apex:actionFunction immediate="true" />

That is we must have immediate=true attribute set so that action function is called immediately. If we do not have this attribute set, SalesForce tries to validate all the standard input elements and if the validation fails, action function is never called.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文