有没有办法获取/编辑Visualforce页面的默认布局?

时间:2013-07-04 19:19:08

标签: autocomplete salesforce jquery-autocomplete visualforce

然后,我可以使用Visualforce编辑salesforce / visualforce页面的默认布局吗?

最终目标是修改“编辑”和“新建”操作的默认布局,以便在外部API的某些字段上添加某种自动完成功能。

我希望能够添加我的javascript代码,而无需完全重写visualforce页面。

1 个答案:

答案 0 :(得分:1)

您可以在主页组件中添加以下jQuery。打开一个新的帐户页面并在发货国家或结算国家/地区字段中输入内容,您将自动完成操作。在下面的脚本中,我有一个国家的静态数组,您可以通过与外部服务器集成来实现动态。

步骤:
1)创建HTML区域和缩小部分类型的主页组件,并添加以下脚本 2)将主页组件添加到主页布局中 3)确保选中“在所有页面上显示自定义边栏组件”选项(设置 - >应用程序设置 - >用户界面)。
4)点击一个新帐户并输入“In”,您将找到自动填充功能。

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css"/>
<script type="text/javascript">
    /*Create a new variable j$ just to avoid any conflicts with other libraries which may be using $.*/
    var j$ = jQuery.noConflict();
    /*Capture the list of countries in a Array.*/
    var countryArray = ['India', 'USA', 'China','FInland','Norway','Netherlands','England','Ukraine','Russia','Japan','Korea','Burma','Srilanka','Iran','Iceland','Canada','Rome','Australia','Armenia','Albania','Afghanisthan'];
    /*on Document ready*/
    j$(document).ready(function(){
        j$("#acc18country, #acc17country").autocomplete({
            source : countryArray
        });
    });
</script>  

enter image description here

希望这个“技巧”适合你!
P.S:如果您使用谷歌浏览器浏览器,那么第一次可能无法正常工作。当您加载页面时,您可能会在地址栏的右侧看到灰色盾牌,单击它并选择“加载不安全的javascript”。为此,请在静态资源中添加javascript和css文件,然后在脚本标记中引用它们。

编辑


现在要从外部API中提取数据,您应该添加以下代码。

<script src="/soap/ajax/26.0/connection.js" type="text/javascript"></script>    
var sid = getCookie('sid'); /*get the session ID cookie*/
var server = "https://" + window.location.host + "/services/Soap/u/26.0";
sforce.connection.init(sid, server);/*Initialize the sforce connection*/
sforce.connection.remoteFunction({
    url: "https://api.github.com/user/",
    requestHeaders: {"Content-Type":"application/json"}
    onSuccess : function(response) {
                      console.log('The response is ' +JSON.stringify(response));
              },
    onFailure : function(response) {
                      console.log("The request Failed with error: " + response)
}); 

但是,在发出此请求之前,请确保在远程站点设置中添加外部API(https://api.github.com)(setup-&gt; administrator-&gt;安全控件 - &gt;远程站点设置)

相关问题