post_wizard.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. // Post Type Wizard - repeatable custom field rows.
  2. //
  3. // Every row contributes exactly one param_name, param_type, param_label,
  4. // param_placeholder and param_required, so the five arrive server side as
  5. // aligned arrays. This is why 'required' is a <select> and not a checkbox --
  6. // an unchecked checkbox submits nothing and would shift every later row.
  7. function addParam() {
  8. var tpl = document.getElementById('wizard-param-template');
  9. var host = document.getElementById('wizard-params');
  10. if ( tpl === null || host === null ) {
  11. console.log('post wizard param template missing');
  12. return false;
  13. }
  14. host.appendChild(document.importNode(tpl.content, true));
  15. return false;
  16. }
  17. function delParam(button) {
  18. var row = button.closest('.wizard-param-row');
  19. if (row) {
  20. row.parentNode.removeChild(row);
  21. }
  22. return false;
  23. }
  24. // Start with one blank row, otherwise the feature isn't discoverable.
  25. document.addEventListener("DOMContentLoaded", function(event) {
  26. if ( document.getElementById('wizard-params') !== null ) {
  27. addParam();
  28. }
  29. });