【问题标题】:Need jquery code to disable Drop downs and people pickers when a option in dropdown is selected in sharepoint在共享点中选择下拉选项时,需要 jquery 代码来禁用下拉菜单和人员选择器
【发布时间】:2012-08-08 20:43:26
【问题描述】:

我正在使用 moss 2007。我创建了一个下拉列,其中包含 3 个选项。如果选择了选项 1 和选项 2,则应禁用下拉菜单和人员选择器,如果选择了选项 3,则应启用下拉菜单和人员选择器列。我提供了页面源代码,由于我是 jquery 的新手,有人可以帮我解决这个问题。

<TR>
            <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
            <nobr>Type of Notification</nobr>
        </H3></TD>
            <TD valign="top" class="ms-formbody" width="400px">
            <!-- FieldName="Type of Notification"
                 FieldInternalName="Type_x0020_of_x0020_Notification"
                 FieldType="SPFieldChoice"
              -->
                <span dir="none"><select name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl07$ctl00$ctl00$ctl04$ctl00$DropDownChoice" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl07_ctl00_ctl00_ctl04_ctl00_DropDownChoice" title="Type of Notification" class="ms-RadioText">
        <option selected="selected" value="Select One">Select One</option>

        <option value="Option1">Option1</option>
        <option value="Option2">Option2</option>
                  <option value="Option3">Option3</option>

    </select><br></span></TD></TR>
<TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Functional Team</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Functional Team"
             FieldInternalName="Mytest"
             FieldType="SPFieldCascadingDropDownListFieldWithFilter"
          -->
            <span dir="none">
        <select name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl16$ctl00$ctl00$ctl04$ctl00$ctl00$Functional Team" onchange="javascript:setTimeout('WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl16$ctl00$ctl00$ctl04$ctl00$ctl00$Functional Team&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))', 0)" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl16_ctl00_ctl00_ctl04_ctl00_ctl00_Functional Team" title="Functional Team Parent" class="ms-input">
    <option selected="selected" value="">Please select an Item</option>
    <option value="Test">Test</option>
    <option value="Other">Other</option> 
</select></span></TD></TR>
<TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Therapeutic Area</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Therapeutic Area"
             FieldInternalName="Therapeutic_x0020_Area"
             FieldType="SPFieldChoice"
          -->
            <span dir="none"><select name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl17$ctl00$ctl00$ctl04$ctl00$DropDownChoice" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl17_ctl00_ctl00_ctl04_ctl00_DropDownChoice" title="Therapeutic Area" class="ms-RadioText">
    <option selected="selected" value="Select One">Select One</option>
    <option value="Anti-Infective">Anti-Infective</option>
    <option value="Other">Other</option> 
</select><br></span></TD>   </TR>

<TR>
        <TD nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">
        <nobr>Admin Name</nobr>
    </H3></TD>
        <TD valign="top" class="ms-formbody" width="400px">
        <!-- FieldName="Admin Name"
             FieldInternalName="Admin_x0020_Name"
             FieldType="SPFieldUser"
          -->
            <span dir="none">
        <input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$HiddenUserFieldValue" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_HiddenUserFieldValue" />
        <span id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField" class="ms-usereditor" NoMatchesText="&lt;No Matching Names>" MoreItemsText="More Names..." RemoveText="Remove" value="" allowEmpty="1" ShowEntityDisplayTextInTextBox="0" EEAfterCallbackClientScript=""><input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$hiddenSpanData" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_hiddenSpanData" /><input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$OriginalEntities" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_OriginalEntities" value="&lt;Entities />" /><input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$HiddenEntityKey" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_HiddenEntityKey" /><input name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$HiddenEntityDisplayText" type="hidden" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_HiddenEntityDisplayText" /><table id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_OuterTable" class="ms-usereditor" cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse;">
    <tr valign="bottom">
        <td valign="top" style="width:90%;"><table cellpadding="0" cellspacing="0" border="0" style="width:100%;table-layout:fixed;">
            <tr>
                <td><div id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv" TabIndex="0" onFocusIn="this._fFocus=1;saveOldEntities('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv')" onClick="onClickRw(true, true);" onChange="updateControlValue('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField')" onFocusOut="this._fFocus=0;" onPaste="dopaste();" AutoPostBack="0" class="ms-inputuserfield" onDragStart="canEvt(event);" onKeyup="return onKeyUpRw('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField');" onCopy="docopy();" onBlur="updateControlValue('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField')" Title="People Picker" onKeyDown="return onKeyDownRw(this, 'ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField', 3, true, event);" contentEditable="true" style="width: 100%; word-wrap: break-work;overflow-x: hidden; background-color: window; color: windowtext;" name="upLevelDiv"></div><textarea name="ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$downlevelTextBox" rows="1" cols="20" id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_downlevelTextBox" class="ms-input" onKeyDown="return onKeyDownRw(this, 'ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField', 3, true, event);" onKeyUp="onKeyUpRw('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField');" Title="People Picker" AutoPostBack="0" style="width:100%;display: none;position: absolute; "></textarea></td>
            </tr>
        </table></td><td align="right" valign="top" nowrap="true" style="padding-left:5px;"><a id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_checkNames" title="Check Names" onclick="var arg=getUplevel('ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField');var ctx='ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField';EntityEditorSetWaitCursor(ctx);WebForm_DoCallback('ctl00$m$g_785c653c_cfa1_4aa5_8060_a84901274cc3$ctl00$ctl04$ctl20$ctl00$ctl00$ctl04$ctl00$ctl00$UserField',arg,EntityEditorHandleCheckNameResult,ctx,EntityEditorHandleCheckNameError,true);return false;" href="javascript:"><img title="Check Names" src="/_layouts/images/checknames.gif" alt="Check Names" style="border-width:0px;" /></a>&nbsp;<a id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_browse" accesskey="B" title="Browse" onclick="__Dialog__ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField(); return false;" href="javascript:"><img title="Browse" src="/_layouts/images/addressbook.gif" alt="Browse" style="border-width:0px;" /></a></td>
    </tr><tr>
        <td colspan="3"><span id="ctl00_m_g_785c653c_cfa1_4aa5_8060_a84901274cc3_ctl00_ctl04_ctl20_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_errorLabel" class="ms-error"></span></td>
    </tr>
</table></span>
    </span>


        </TD>
    </TR>

【问题讨论】:

标签: jquery sharepoint sharepoint-2007


【解决方案1】:

不确定如何禁用您的人员选择器(没有从您的 html 中看到/理解)。但这将处理下拉菜单。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
<script type="text/javascript">
    $(function(){
        $('select[title="Type of Notification"]').change(function(){
            if($(this).val() == "Option1" || $(this).val() == "Option2")
            {
                $('select').not(this).attr('disabled', 'disabled');
            }else if($(this).val() == "Option3"){
                $('select').not(this).removeAttr('disabled');
            }
        });
    });
</script>

【讨论】:

  • PeopleEditor 是一个 Sharepoint .NET 控件。这是一个巨大的 html 混乱,有 4 个输入、一个 textarea、contentEditable div、一些图像按钮……所有这些都包含在几个表格和跨度中……这并不好玩。
  • @kingjiv - 看起来不像,因为这段代码很糟糕!!!我无法想象为什么您需要输入超过 115 个字符的名称!更不用说所有 CAPS html 节点...
【解决方案2】:

PeopleEditor 相当复杂和烦人。您需要处理多个组件才能禁用它。在 IE 中有一个 contentEditable div 这是您可以输入的主要输入。您还可以处理带有onclick 的图像按钮。然后在非IE浏览器中我相信它使用textarea

你需要做这样的事情(未经测试,你可能需要调整它):

$("span[id$='_UserField']").find(":input").val("").attr("disabled",true); 

以上将清除和禁用控件使用的所有输入字段(包括textarea)。

然后你需要处理内容可编辑的div。我不确定您是否可以disable 它或者您是否需要像这样更改contentEditable 属性:

$("div[id$='_UserField_upLevelDiv']").text("").attr("contentEditable",false);

最后是图片。图像被包装在带有 onclick 的 a 标记中。我的建议是像这样隐藏它们:

$("span[id$='_UserField']").find("img").hide();

希望对您有所帮助。如果你能侥幸逃脱,那么隐藏整个事情会容易得多。

【讨论】:

  • +1,人员选择器是一场噩梦。我有一个related post 可能会有所帮助。
【解决方案3】:

另一种选择是使用SPUtility.js(完全公开,我维护这个开源库)。它依赖于 Prototype.js,所以你可能不感兴趣,因为你使用的是 jQuery。

它支持隐藏和/或禁用许多不同的字段类型.. 包括人员选择器:

// make a people field read only
SPUtility.GetSPField('Assigned To').MakeReadOnly();
// hide the people field
SPUtility.GetSPField('Assigned To').Hide();

【讨论】:

    猜你喜欢
    • 2012-10-20
    • 2013-06-13
    • 1970-01-01
    • 2020-10-18
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    相关资源
    最近更新 更多