Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Existing Code Alert #84

Open
Pauldro opened this issue Jun 19, 2020 · 0 comments
Open

Existing Code Alert #84

Pauldro opened this issue Jun 19, 2020 · 0 comments
Assignees

Comments

@Pauldro
Copy link
Member

Pauldro commented Jun 19, 2020

  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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants