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

Edit page components integration fixing #2510

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dt-tags fixes on edit detail page and code remove for duplicate check…
… on contact and email fields related
  • Loading branch information
Ashima-Arora committed May 31, 2024
commit 17fcbab752875d5432e740e394ede6974d945b33
91 changes: 0 additions & 91 deletions dt-assets/js/new-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -1860,97 +1860,6 @@ jQuery(function ($) {
}
}

// Check for phone and email duplication
let non_duplicable_fields = ['contact_phone', 'contact_email'];
$.each(non_duplicable_fields, function (field_key, field_type) {
if (window.new_record_localized.post_type_settings.fields[field_type]) {
var field_name =
window.new_record_localized.post_type_settings.fields[field_type].name;
$(`input[data-field="${field_type}"]`).attr(
`data-${field_type}-index`,
'0',
);
$(`input[data-field="${field_type}"]`).after(
`<span class="loading-spinner" data-${field_type}-index="0" style="margin: 0.5rem;"></span>`,
);
$(`input[data-field="${field_type}"]`).parent().after(`
<div class="communication-channel-error" data-${field_type}-index="0" style="display: none;">
${window.new_record_localized.translations.value_already_exists.replace(
'%s',
field_name,
)}:
<span class="duplicate-ids" data-${field_type}-index="0" style="color: #3f729b;"></span>
</div>`);
}
});

function check_field_value_exists(field_type, element_index) {
var email = $(`input[data-${field_type}-index="${element_index}"]`).val();
$(`.loading-spinner[data-${field_type}-index="${element_index}"]`).attr(
'class',
'loading-spinner active',
);
if (!email) {
$(
`.communication-channel-error[data-${field_type}-index="${element_index}"]`,
).hide();
$(`.loading-spinner[data-${field_type}-index="${element_index}"]`).attr(
'class',
'loading-spinner',
);
return;
}
var post_type = window.wpApiShare.post_type;
var data = { communication_channel: `${field_type}`, field_value: email };
jQuery
.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
url:
window.wpApiShare.root +
`dt-posts/v2/${post_type}/check_field_value_exists`,
beforeSend: (xhr) => {
xhr.setRequestHeader('X-WP-Nonce', window.wpApiShare.nonce);
},
})
.then((result) => {
if (!$.isEmptyObject(result)) {
var duplicate_ids_html = '';
$.each(result, function (k, v) {
if (k > 0) {
duplicate_ids_html += ', ';
}
duplicate_ids_html += `<a href="/${post_type}/${v.post_id}" target="_blank">${window.new_record_localized.translations.contact} #${v.post_id}</a>`;
});
$(`.duplicate-ids[data-${field_type}-index="${element_index}"]`).html(
duplicate_ids_html,
);
$(
`.communication-channel-error[data-${field_type}-index="${element_index}"]`,
).show();
} else {
$(
`.communication-channel-error[data-${field_type}-index="${element_index}"]`,
).hide();
$(`.duplicate-ids[data-${field_type}-index="${element_index}"]`).html(
'',
);
}
$(`.loading-spinner[data-${field_type}-index="${element_index}"]`).attr(
'class',
'loading-spinner',
);
});
}

$('.form-fields').on('change', 'input[data-field^="contact_"]', function () {
var post_type = $(this).data('field');
var element_index = $(this).data(`${post_type}-index`);
check_field_value_exists(post_type, element_index);
});

/**
* ============== [ BULK RECORD ADDING FUNCTIONALITY ] ==============
*/
Expand Down
Loading
Loading