gpt4 book ai didi

drop-down-menu - 露天分享中的动态选择

转载 作者:行者123 更新时间:2023-12-04 04:33:09 26 4
gpt4 key购买 nike

对于 Alfresco 共享中的表单,我想要一个下拉框,其中填充了自定义选项,具体取决于表单中早期字段的值。

我的表单至少有两个字段。第一个是文本框,必须在其中输入唯一代码。完成后,第二个,一个选择框,必须使用输入的代码加载它的选项。

支持此要求的数据存储在数据列表中。我还通过网络脚本(沿着 /getOptions/{uniqueCode 的行,返回有效选项的 JSON 数组)使其可用。

现在,我对如何构建将监视代码文本字段上的状态更改并重新加载下拉框的表单部分感到困惑。我可以想到一些 javascript,但我什至不知道从哪里开始更改/添加文件。

我已经浏览了 FDK ,在那里我找到了 selectone ftl。不幸的是,这仅支持固定选项。

我的实现基于我选择的答案

这与我已经在做的非常相似,我曾希望能够在服务器端做到这一点,而不包括额外的往返。到目前为止,这是我拥有的最好的。

share-config-custom.xml

我在此处定义表单,并将我想成为我的选择的属性指向我自己的自定义字段模板。我传递了一个参数 ds给它,dataSource ,它保存了我的网页脚本的路径。

<config evaluator="node-type" condition="my:contentType">
<forms>
<form>
<field-visibility>
<show id="my:code" />
<show id="my:description" />
</field-visibility>
<appearance>
<set id="general" appearance="bordered-panel" label="General" />
<field id="my:description" set="general">
<control template="/org/alfresco/components/form/controls/customSelectone.ftl">
<control-param name="ds">/alfresco/service/mark/cache/options</control-param>
</control>
</field>
</appearance>
</form>
</forms>

customSelectone.ftl

我的自定义 ftl 有三个主要步骤。首先,它接收我从 share config custom 传递的 ftl 参数并将其分配给一个局部变量。然后它放置一个 html <select> box 作为一个字段,最后,它执行对我的 webscript 的调用以获取可能的选项。

范围
<#if field.control.params.ds?exists><#assign ds=field.control.params.ds><#else><#assign ds=''></#if>
html
<style type="text/css">
#${fieldHtmlId}-AutoComplete {
width:${width}; /* set width here or else widget will expand to fit its container */
padding-bottom:2em;
}
</style>

<div class="form-field">
<#-- view form -->
<#if form.mode == "view">
<div class="viewmode-field">
<#if field.mandatory && !(field.value?is_number) && field.value == "">
<span class="incomplete-warning"><img src="${url.context}/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
</#if>
<span class="viewmode-label">${field.label?html}:</span>
<span class="viewmode-value">${field.value?html}</span>
</div>
<#else>
<#-- alternative: if form.mode == "edit" -->
<#-- Create/edit form -->
<label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<div id="${fieldHtmlId}-AutoComplete">
<#-- Label to hold error messages from the javascript -->
<p style="color:red" id="${fieldHtmlId}-scriptError"></p>
<select id="${fieldHtmlId}" name="${field.name}"
<#if field.control.params.styleClass?exists>class="${field.control.params.styleClass}"</#if>
<#if field.description?exists>title="${field.description}"</#if>
<#if field.control.params.size?exists>size="${field.control.params.size}"</#if>
<#if field.disabled>disabled="true"</#if> >
<#-- Add the field's current value if it has one as an option -->
<option>${field.value}</option>
</select>
<div id="${fieldHtmlId}-Container"></div>
</div>
</div>

Javascript
<script type="text/javascript">//<![CDATA[
(function()
{
<#-- This references the code field from the form model. For this, the -->
<#-- share config must be set to show the field for this form. -->
<#if form.fields.prop_my_code??>
var code = "${form.fields.prop_my_code.value}";
<#else>
var code = 0;
</#if>

// get code
if(code === null || code === "") {
document.getElementById('${fieldHtmlId}-scriptError').innerHTML = 'No description available.';
return;
}

// Create webscript connection using yui connection manager
// Note that a much more elegant way to call webscripts using Alfresco.util is
// available in the answers here.
var AjaxConnectionManager = {
handleSuccess:function(o) {
console.log('response: '+o.responseText);
this.processResult(o);
},

handleFailure:function(o) {
var selectBox = document.getElementById('${fieldHtmlId}');
var i;

document.getElementById('${fieldHtmlId}-scriptError').innerHTML = 'Descriptions not available.';
},

startRequest:function() {
console.log('webscript call to ${ds} with params code='+code);
YAHOO.util.Connect.asyncRequest('GET', "${ds}?typecode="+code, callback, null);
},

processResult:function(o) {
var selectBox = document.getElementById('${fieldHtmlId}');
var jso = JSON.parse(o.responseText);
var types = jso.types;
console.log('adding '+types.length+' types to selectbox '+selectBox);
var i;

for(i=0;i<types.length;i++) {
// If the current field's value is equal to this value, don't add it.
if(types[i] === null || types[i] === '${field.value}') {
continue;
}
selectBox.add(new Option(types[i], types[i]));
}
}
}

// Define callback methods
var callback = {
success:AjaxConnectionManager.handleSuccess,
failure:AjaxConnectionManager.handleFailure,
scope: AjaxConnectionManager
};

// Call webscript
AjaxConnectionManager.startRequest();
})();
//]]></script>
<#-- This closes the form.mode != "create" condition, so the js is only executed when in edit/create mode. -->
</#if>

最佳答案

我以前有过类似的任务。
首先你需要在你的配置xml中定义一个自定义模板

<config evaluator="node-type" condition="my:type">
<forms>
<form>
<field-visibility>
<show id="cm:name" />
<show id="my:options" />
<show id="cm:created" />
<show id="cm:creator" />
<show id="cm:modified" />
<show id="cm:modifier" />
</field-visibility>
<appearance>
<field id="my:options">
<control template="/org/alfresco/components/form/controls/custom/custom-options.ftl" />
</field>
</appearance>
</form>
</forms>
</config>

这里发生的是表单引擎将查找 custom-options.ftl渲染 my:options类型 my:type . custom-options.ftl将包含显示您的数据所需的 html,当然还有对 javascript 类的调用,该类将从您的 web 脚本加载您的列表。
所以它看起来像这样
<#assign controlId = fieldHtmlId + "-cntrl">
<script type="text/javascript">//<![CDATA[
// Here you could call your webscript and load your list
</script>

<div id="${controlId}" class="form-field">
<label for="${fieldHtmlId}">${msg("form.control.my-options.label")}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
<#if field.description??>title="${field.description}"</#if>
<#if field.control.params.size??>size="${field.control.params.size}"</#if>
<#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
<#if field.control.params.style??>style="${field.control.params.style}"</#if>>
</select>
<@formLib.renderFieldHelp field=field />
</div>

关于drop-down-menu - 露天分享中的动态选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17150808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com