Skip to content

Commit

Permalink
valid email input when save form.
Browse files Browse the repository at this point in the history
  • Loading branch information
LongTrong-exe committed May 26, 2022
1 parent e8b400e commit 06f20a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
21 changes: 18 additions & 3 deletions js/ajax_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,24 @@ onOffice.ajaxSaver = function(outerDiv) {
(function() {
this.register = function() {
var proto = this;
this._outerDiv.find('#send_ajax').on('click', function() {
window.scrollTo(0, 0);
proto.save();
var form = $("form");
var typesNeedValid = ['email'];

form.submit(function (e) {
e.preventDefault();
});
this._outerDiv.find('#send_ajax').on('click', function () {
var isValid = true;
form.find(':input').each(function (index, input) {
if (!input.checkValidity() && $.inArray(input.getAttribute('type'), typesNeedValid) !== -1) {
isValid = false;
return false;
}
});
if (isValid) {
window.scrollTo(0, 0);
proto.save();
}
});
};

Expand Down
2 changes: 2 additions & 0 deletions plugin/Gui/AdminPageSettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function addAdminNoticeWrapper()

public function renderContent()
{
echo '<form method="post">';
do_action('add_meta_boxes', get_current_screen()->id, null);
$this->generateMetaBoxes();

Expand Down Expand Up @@ -185,6 +186,7 @@ public function renderContent()
echo '</div>';
do_settings_sections( $this->getPageSlug() );
submit_button(null, 'primary', 'send_ajax');
echo '</form>';

echo '<script>'
.'jQuery(document).ready(function(){'
Expand Down
4 changes: 2 additions & 2 deletions plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function createInputModelRecipient()

$pInputModelFormRecipient = $this->getInputModelDBFactory()->create
(InputModelDBFactoryConfigForm::INPUT_FORM_RECIPIENT, $labelRecipient);
$pInputModelFormRecipient->setHtmlType(InputModelOption::HTML_TYPE_TEXT);
$pInputModelFormRecipient->setHtmlType(InputModelOption::HTML_TYPE_EMAIL);
$pInputModelFormRecipient->setValue($selectedRecipient);
$pInputModelFormRecipient->setDeactivate(true);

Expand All @@ -322,7 +322,7 @@ public function createInputModelRecipientContactForm()

$pInputModelFormRecipient = $this->getInputModelDBFactory()->create
(InputModelDBFactoryConfigForm::INPUT_FORM_RECIPIENT, $labelRecipient);
$pInputModelFormRecipient->setHtmlType(InputModelOption::HTML_TYPE_TEXT);
$pInputModelFormRecipient->setHtmlType(InputModelOption::HTML_TYPE_EMAIL);
$pInputModelFormRecipient->setValue($selectedRecipient);
$pInputModelFormRecipient->setDeactivate(true);
$pInputModelFormRecipient->setHintHtml(__('Note that if the contact form is on an estate detail page and the estate has a contact person, the email will be sent to their email address. Otherwise this email address will receive the email.', 'onoffice-for-wp-websites'));
Expand Down

0 comments on commit 06f20a6

Please sign in to comment.