2016-06-16 3 views
0

Я хотел бы создать скрипт java, который сделает поле комментария (textarea) обязательным, когда вы выберете список выбора, теперь я просто сделаю необходимый значок рядом с кодом комментария ниже и застрял на нем ниже.JavaScript обязательный на основе выбора. Список выбора

Спасибо в советы для всех помощи

код, что я писал:

<select id="ddlViewBy"> 
<option value="1">AJS.$("#comment-popup").parent().children('label').append('<span class="aui-icon icon-required"></span>');</option> 

Исходный код моего веб-сайта:

<form action="/jira/rest/tempo-rest/1.0/worklogs/{issueKey}" class="aui tempo-form" data-form-type="" name="tempo-panel-form-popup" method="post"> 
<div class="form-body" style="max-height: 393px;"> 
    <input type="hidden" name="id" value=""> 
    <input type="hidden" name="type" value="issue"> 
    <input type="hidden" name="use-ISO8061-week-numbers" value="false"> 
    <input type="hidden" name="ansidate" value=""> 
    <input type="hidden" name="ansienddate" value=""> 
    <input type="hidden" name="selected-panel" value=""> 
    <input type="hidden" name="analytics-origin-page" value=""> 
    <input type="hidden" name="analytics-origin-view" value=""> 
    <input type="hidden" name="analytics-origin-action" value=""> 
    <input type="hidden" name="startTimeEnabled" value="false"> 
    <input type="hidden" name="tracker" value="false"> 
    <input type="hidden" name="preSelectedIssue" class="tempoIssueKey" value="AB-5048"> 
    <input type="hidden" name="planning" value="false"> 
    <div class="field-group"> 
     <label for="user-picker-popup">User</label> 
     <div class="tempo-pickers"> 
      <div class="aui-ss medium aui-ss-has-entity-icon" id="user-picker-popup-single-select"> 
       <input autocomplete="off" class="text aui-ss-field ajs-dirty-warning-exempt" id="user-picker-popup-field"> 
       <div class="aui-list" id="user-picker-popup-suggestions" tabindex="-1"></div><span class="icon aui-ss-icon noloading drop-menu"><span>More</span></span><img class="aui-ss-entity-icon" alt="" src="google.pl"> </div> 
      <select id="user-picker-popup" class="plan-user-picker dialog-user-picker aui-ss-select" name="user" data-container-class="medium" data-counter="popup" data-input-text="Jon Smith" multiple="multiple" style="display: none;"> 
       <optgroup id="tempo-user-suggested-popup" data-weight="0" label=""> 
        <option selected="selected" style="background-image:url(/jira/secure/useravatar?size=small&amp;ownerId=jsmith&amp;avatarId=12927)" value="jsmith">Jon Smith</option> 
       </optgroup> 
      </select> 
     </div> 
    </div> 
    <div class="field-group tempo-issue-container"> 
     <label for="tempo-issue-picker-popup">Issue </label> 
     <div class="aui-ss" id="tempo-issue-picker-popup-single-select"> 
      <input autocomplete="off" class="text aui-ss-field ajs-dirty-warning-exempt" id="tempo-issue-picker-popup-field"> 
      <div class="aui-list" id="tempo-issue-picker-popup-suggestions" tabindex="-1"></div><span class="icon aui-ss-icon noloading drop-menu"><span>More</span></span> 
     </div> 
     <select id="tempo-issue-picker-popup" class="tempo-issue-picker tempo-picker-all-issues tempo-issue-picker-logwork aui-ss-select" name="issue" multiple="multiple" style="display: none;"> 
      <option selected="selected" value="AB-5048">AB-5048 - Holiday - Jon Smith 2016-06-13-2016-06-13</option> 
     </select> 
    </div> 
    <div class="tempo-datepicker"> 
     <div class="field-group tempo-show-period"> 
      <label for="showPeriod-popup">Period</label> 
      <div class="checkbox"> 
       <input id="showPeriod-popup" name="showperiod" type="checkbox" value="showperiod" class="showperiod tempo-show-period"> </div> 
     </div> 
     <div class="field-group datepicker "> 
      <label for="datefield-popup">Date</label> 
      <input type="text" id="datefield-popup" name="date" size="7" value="2016-06-09" class="text medium-field"> <span id="datefield-trigger-popup" class="aui-icon icon-date tempo-datepicker-trigger" tabindex="0">Select a date</span> </div> 
     <div class="field-group enddate datepicker " style="display: none;"> 
      <label for="enddate-popup">End date</label> 
      <input type="text" id="enddate-popup" name="enddate" size="7" value="2016-06-09" class="text medium-field"> <span id="enddate-trigger-popup" class="aui-icon icon-date tempo-datepicker-trigger" tabindex="0">Select a date</span> </div> 
    </div> 
    <div class="tempo-timepicker resetable"> 
     <div class="field-group tempo-worked-hours"> 
      <label class="timepicker-label" tmp="Work per day" for="time-popup">Worked </label> 
      <input autocomplete="off" type="text" id="time-popup" name="time" size="3" value="" class="tempo-time text short-field"> </div> 
     <div class="remaining-and-billed-hours-container"> 
      <div class="field-group tempo-logged-work"> 
       <label for="totalSpent-popup">Logged</label> <span class="totalSpent" id="totalSpent-popup">8h</span> </div> 
      <div class="field-group tempo-remaining-estimate" style="clear: left;"> 
       <label for="remainingEstimate-popup">Remaining estimate </label> 
       <input type="hidden" id="remainingEstimateHidden-popup" size="3" maxlength="6" value=""> 
       <input type="text" id="remainingEstimate-popup" name="remainingEstimate" size="3" maxlength="6" value="" class="validate remaining resetable text short-field"> </div> 
      <div class="field-group tempo-original-estimate"> 
       <label for="originalEstimate-popup">Original estimate</label> <span class="originalEstimate" id="originalEstimate-popup"></span> </div> 
     </div> 
    </div> 
    <div class="field-group resetable"> 
     <label for="comment-popup">Description</label> 
     <textarea id="comment-popup" name="comment" class="tempo-comment textarea resetable"></textarea> 
    </div> 
    <ul id="errors-popup" class="error-list"> </ul> 
    <p style="width: 97%; margin: 0 0 10px 0;" id="tempo-logwork-issue-hint" class="hint-container overflow-ellipsis" title="Pressing w also opens this dialog box"> <a class="shortcut-tip-trigger" title="Click to view all shortcuts" href="#" tabindex="-1">Shortcut tip:</a> Pressing <strong>w</strong> also opens this dialog box </p> 
</div> 
<div class="buttons-container form-footer"> <span id="logwork-spinner" class="aui-icon aui-icon-wait" style="display:none"></span> 
    <div class="buttons"><span class="icon throbber"></span> 
     <input type="checkbox" id="issue-add-another" class="tempo-add-another-input" value="Another"> 
     <label for="issue-add-another" class="tempo-add-another-label"> Log another </label> 
     <input type="submit" id="issue-add-button" class="button button-panel-button" accesskey="s" value="Log Work"> <a id="tempo-logwork-issue-cancel" class="cancel" href="/jira/browse/AB-5048?" accesskey="'">Cancel</a> </div> 
</div> 

ответ

0

выглядит как вы работаете внутри Atlassian продукт.

Так вы сделать HTML поле обязательным Вы можете добавить необходимый атрибут , который является работоспособным во всех современных браузерах, кроме сафари я вещь, пожалуйста, проверьте этот

в JS (Jquery), чтобы добавить атрибут будет

$('#comment-popup').attr('required', 'required'); 

если это AUI-выбери или AUI вход читать документы там https://docs.atlassian.com/aui/latest/docs/single-select.html на выборе, например, существует непустой атрибут

Смежные вопросы