Skip to content

Existing Code Alert #84

@Pauldro

Description

@Pauldro
  1. Edit form.twig add the data-code attribute like this data-code=""
    it should look like
    <form action="{{ page.url }}" method="POST" id="code-edit-form">

  2. create populate_edit_from_button(button, modal) function
    NOTE:: EDIT so it applies to the code table so it populates the right fields

	function populate_edit_from_button(button, modal) {
		var code = button.data('code').toString();
		var description = button.data('description').toString();

		modal.find('form').attr('data-code', code);
		modal.find('input[name=code]').val(code);
		modal.find('input[name=description]').val(description);
		modal.find('select[name=surcharge]').val(button.data('surcharge'));
		modal.find('input[name=percentage]').val(button.data('percentage'));

		if (code.length) {
			modal.find('.modal-title').text('Editing Code ' + code);
			modal.find('input[name=code]').prop("readonly", true);
			modal.find('input[name=description]').focus();
		} else {
			modal.find('.modal-title').text('Adding a new Code');
			modal.find('input[name=code]').prop("readonly", false);
			modal.find('input[name=code]').focus();
		}
	}
  1. Edit the $('#edit-code-modal').on('shown.bs.modal', function (event) { function to use the new populate_edit_from_button(button, modal) function

  2. Add function

$("body").on("click", ".swal-edit-code", function(e) {
		var button = $(this);
		var code = button.data('code');
		var edit_button = $('button[data-code='+code+']');
		var modal = $('#edit-code-modal');
		populate_edit_from_button(edit_button, modal);
		swal2.close();
	});
  1. Edit $("body").on("change", "input[name=code]", function(e) { the then((result) => { part should now match
var modal = $('#edit-code-modal');

				if (result.value) {
					var button = $('button[data-code="'+codeID+'"]');
					populate_edit_from_button(button, modal);
				} else if (result.dismiss === Swal.DismissReason.cancel) {
					modal.modal('hide');
				}
  1. The validate method should now have something that matches this (change description for code table)
    content += '<button type="button" class="btn btn-secondary swal-edit-code" data-code="'+codeID+'">Edit Customer Price Code '+ codeID +'</button>';

  2. jform.data('codeid') should now be jform.attr('data-code')

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions