У меня есть два флажка «Принять» и «Отклонить» и кнопка «Отправить».Когда я нажимаю на кнопку «Отправить», она должна поставить галочку. - PullRequest
0 голосов
/ 26 сентября 2019
{ field: "Accept", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.AcceptChk), "template": "<input type=\"checkbox\" # if (checkCommentsAccept(data.Comments)) { #disabled=\"disabled\" # } # />" },
{ field: "Decline", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.DeclineChk), "template": "<input type=\"checkbox\" # if (checkCommentsDecline(data.Comments)) { #disabled=\"disabled\" # } # />" },
{ field: "Item", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Item) },
{ field: "PartID", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.PartID) },
{ field: "Description", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Description), width: '300px' },
{ field: "SubPart", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPart) },
{ field: "SubPartDescription", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPartDescription) },
{ field: "BusinessPartner", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.BusinessPartner) },
{ field: "ReqDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.ReqDelTM) },
{ field: "EarDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.EarDelTM) },
{ field: "EarDelDate", title: "Ear Del Date", hidden: true },
{ field: "Comments", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Comments) }

Когда я нажимаю кнопку «Отправить», следует проверить, установлен ли флажок «Принять» или нет, если установлен флажок, у меня есть некоторая логика.Если флажок отклонения установлен, то у меня есть другая логика.

Ответы [ 2 ]

0 голосов
/ 26 сентября 2019

если есть флажок, который вы могли бы реализовать, чтобы был установлен только один флажок, верно?, В противном случае может существовать вероятность того, что флажок Принять и отклонить оба флажка установлен,

при условии, что вы реализовали логику флажка одиночного выбора

$( "form" ).submit(function( event ) {
  event.preventDefault();
  if($("input[type='checkbox']:checked")[0].val() == 'Allow'){
    // things to done on allowed
  }else  if($("input[type='checkbox']:checked")[0].val() == 'Declined'){
    // things to done on declined
  }else{
    // rest things 
  }
});

вам может потребоваться немного изменить код, но он будет работать логически в соответствии с вашими потребностями.

0 голосов
/ 26 сентября 2019

Это на самом деле сводится к тому, как остановить событие от выполнения его собственного поведения.

Если нажата кнопка отправки, запускается событие формы submit.Таким образом, если ваш флажок не установлен в это время, вам нужно остановить событие, что делается с помощью event.preventDefault().Если флажок установлен, просто ничего не делайте и разрешите отправку.

Вот пример:

// Get reference to the checkbox
let chk = document.querySelector("input[type='checkbox']");

// Set up event handler on the form
document.querySelector("form").addEventListener("submit", function(event){

  // Check to see if the checkbox was not checked
  if(!chk.checked){
    event.preventDefault();  // Stop the submit event
    alert("You must agree before continuing.");
    return;
  }
  
  // If we get to this point in the code, the checkox was checked
  // and the form will submit.

});
<form action="http://example.com" method="post">
  <input type="checkbox" name="chkAgree" 
         id="chkAgree" value="agree">
  I agree to the terms of this site.
  <br>
  <button>Submit</button>
</form>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...