LimitUserSelectionToTwoItems.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. define(function () {
  2. "use strict";
  3. function validatePromptValue() {
  4. };
  5. validatePromptValue.prototype.draw = function (oControlHost) {
  6. //this.m_sName = oControlHost.configuration.name || "listBoxPL";
  7. var el = oControlHost.container;
  8. el.innerHTML =
  9. '<style>' +
  10. '.MyPromptButton' +
  11. '{' +
  12. 'background-color: white;' +
  13. 'border: 2px solid #4178BE;' +
  14. 'color: #4178be;' +
  15. 'font-size: 14px;' +
  16. 'height: 32px;' +
  17. 'width: 120px;' +
  18. 'margin-left: 20px;' +
  19. 'cursor: pointer;' +
  20. '} ' +
  21. '.MyPromptButton:hover' +
  22. '{' +
  23. 'background-color: #4178BE;' +
  24. 'color: white;' +
  25. '}' +
  26. '</style>' +
  27. '<button class="MyPromptButton btn1">Finish</button>' +
  28. '<button class="MyPromptButton btn2">Cancel</button>';
  29. el.querySelector(".btn1").onclick = this.MyPromptButtonFinishClick.bind(this, oControlHost);
  30. el.querySelector(".btn2").onclick = oControlHost.cancel.bind(oControlHost);
  31. };
  32. validatePromptValue.prototype.MyPromptButtonFinishClick = function (oControlHost) {
  33. var productLinePrompt = oControlHost.page.getControlByName("listBoxPL");
  34. var plValues = productLinePrompt.getValues();
  35. if (plValues && plValues.length > 2) {
  36. alert("You cannot select more than 2 Product lines.");
  37. return false;
  38. }
  39. else {
  40. // Submit the prompt values calling the finish method
  41. oControlHost.finish()
  42. }
  43. };
  44. return validatePromptValue;
  45. });