How to add custom checkbox with event in customer registration Magento 2?
I'm working on creating a custom checkbox with an event
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
1)when the checkbox is ticked need to show
extra two fields in customer registration
2)How I change the checkbox as optional one
How I can do it ???
Any ideas?
Edit 1:
addtional.phtml
<div id="idofyourinputwrapper">
<div class="field skype required">
<label class="label" for="skype2">
<span><?= $block->escapeHtml(__('Check now')) ?></span>
</label>
<div class="control">
<input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}">
</div>
</div>
</div>
magento2 javascript custom-field checkbox
add a comment |
I'm working on creating a custom checkbox with an event
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
1)when the checkbox is ticked need to show
extra two fields in customer registration
2)How I change the checkbox as optional one
How I can do it ???
Any ideas?
Edit 1:
addtional.phtml
<div id="idofyourinputwrapper">
<div class="field skype required">
<label class="label" for="skype2">
<span><?= $block->escapeHtml(__('Check now')) ?></span>
</label>
<div class="control">
<input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}">
</div>
</div>
</div>
magento2 javascript custom-field checkbox
hm wait..........
– prabhakaran7
3 hours ago
add a comment |
I'm working on creating a custom checkbox with an event
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
1)when the checkbox is ticked need to show
extra two fields in customer registration
2)How I change the checkbox as optional one
How I can do it ???
Any ideas?
Edit 1:
addtional.phtml
<div id="idofyourinputwrapper">
<div class="field skype required">
<label class="label" for="skype2">
<span><?= $block->escapeHtml(__('Check now')) ?></span>
</label>
<div class="control">
<input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}">
</div>
</div>
</div>
magento2 javascript custom-field checkbox
I'm working on creating a custom checkbox with an event
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
1)when the checkbox is ticked need to show
extra two fields in customer registration
2)How I change the checkbox as optional one
How I can do it ???
Any ideas?
Edit 1:
addtional.phtml
<div id="idofyourinputwrapper">
<div class="field skype required">
<label class="label" for="skype2">
<span><?= $block->escapeHtml(__('Check now')) ?></span>
</label>
<div class="control">
<input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}">
</div>
</div>
</div>
magento2 javascript custom-field checkbox
magento2 javascript custom-field checkbox
edited 2 hours ago
prabhakaran7
asked 5 hours ago
prabhakaran7prabhakaran7
1799
1799
hm wait..........
– prabhakaran7
3 hours ago
add a comment |
hm wait..........
– prabhakaran7
3 hours ago
hm wait..........
– prabhakaran7
3 hours ago
hm wait..........
– prabhakaran7
3 hours ago
add a comment |
2 Answers
2
active
oldest
votes
Try this,
Replace this
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
with this
<div class="field tcagreecreateaccount">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" class="input-checkbox checkbox" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
then add the below script in your phtml
require(['jquery'],function($) {
$(document).ready(function () {
var ckbox = $('#tcagreecreateaccount');
$('#tcagreecreateaccount').on('click',function () {
if (ckbox.is(':checked')) {
$('#idofyourinputwrapper').show(); //idofyourinputwrapper is your input wrapper
} else {
$('#idofyourinputwrapper').hide();
}
});
});
});
wrap your two inputs with a div like below.
<div id="idofyourinputwrapper">
Hope this helps :)
i tried but not event working....
– prabhakaran7
3 hours ago
Event?? what that mean? The above code do, remove required field and when you click checkbox it will show and hide the below field. Please update your code
– Prathap Gunasekaran
3 hours ago
i added this not working <div id="idofyourinputwrapper"> <div class="field skype required"> <label class="label" for="skype2"> <span><?= $block->escapeHtml(__('Check now')) ?></span> </label> <div class="control"> <input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}"> </div> </div> </div>
– prabhakaran7
3 hours ago
i set is required:false
– prabhakaran7
3 hours ago
Have you added script ??
– Prathap Gunasekaran
3 hours ago
|
show 11 more comments
Firstly remove required from your checkbox and other two attributes.
Both attributes depending on checkbox click will be hidden by default (can do with CSS or JS).
On checkbox click, you can use jQuery to display both attributes.
done.........................
– prabhakaran7
31 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266159%2fhow-to-add-custom-checkbox-with-event-in-customer-registration-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this,
Replace this
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
with this
<div class="field tcagreecreateaccount">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" class="input-checkbox checkbox" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
then add the below script in your phtml
require(['jquery'],function($) {
$(document).ready(function () {
var ckbox = $('#tcagreecreateaccount');
$('#tcagreecreateaccount').on('click',function () {
if (ckbox.is(':checked')) {
$('#idofyourinputwrapper').show(); //idofyourinputwrapper is your input wrapper
} else {
$('#idofyourinputwrapper').hide();
}
});
});
});
wrap your two inputs with a div like below.
<div id="idofyourinputwrapper">
Hope this helps :)
i tried but not event working....
– prabhakaran7
3 hours ago
Event?? what that mean? The above code do, remove required field and when you click checkbox it will show and hide the below field. Please update your code
– Prathap Gunasekaran
3 hours ago
i added this not working <div id="idofyourinputwrapper"> <div class="field skype required"> <label class="label" for="skype2"> <span><?= $block->escapeHtml(__('Check now')) ?></span> </label> <div class="control"> <input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}"> </div> </div> </div>
– prabhakaran7
3 hours ago
i set is required:false
– prabhakaran7
3 hours ago
Have you added script ??
– Prathap Gunasekaran
3 hours ago
|
show 11 more comments
Try this,
Replace this
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
with this
<div class="field tcagreecreateaccount">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" class="input-checkbox checkbox" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
then add the below script in your phtml
require(['jquery'],function($) {
$(document).ready(function () {
var ckbox = $('#tcagreecreateaccount');
$('#tcagreecreateaccount').on('click',function () {
if (ckbox.is(':checked')) {
$('#idofyourinputwrapper').show(); //idofyourinputwrapper is your input wrapper
} else {
$('#idofyourinputwrapper').hide();
}
});
});
});
wrap your two inputs with a div like below.
<div id="idofyourinputwrapper">
Hope this helps :)
i tried but not event working....
– prabhakaran7
3 hours ago
Event?? what that mean? The above code do, remove required field and when you click checkbox it will show and hide the below field. Please update your code
– Prathap Gunasekaran
3 hours ago
i added this not working <div id="idofyourinputwrapper"> <div class="field skype required"> <label class="label" for="skype2"> <span><?= $block->escapeHtml(__('Check now')) ?></span> </label> <div class="control"> <input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}"> </div> </div> </div>
– prabhakaran7
3 hours ago
i set is required:false
– prabhakaran7
3 hours ago
Have you added script ??
– Prathap Gunasekaran
3 hours ago
|
show 11 more comments
Try this,
Replace this
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
with this
<div class="field tcagreecreateaccount">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" class="input-checkbox checkbox" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
then add the below script in your phtml
require(['jquery'],function($) {
$(document).ready(function () {
var ckbox = $('#tcagreecreateaccount');
$('#tcagreecreateaccount').on('click',function () {
if (ckbox.is(':checked')) {
$('#idofyourinputwrapper').show(); //idofyourinputwrapper is your input wrapper
} else {
$('#idofyourinputwrapper').hide();
}
});
});
});
wrap your two inputs with a div like below.
<div id="idofyourinputwrapper">
Hope this helps :)
Try this,
Replace this
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:false}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
with this
<div class="field tcagreecreateaccount">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" class="input-checkbox checkbox" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom checkbox') ?>
</label>
</div>
</div>
then add the below script in your phtml
require(['jquery'],function($) {
$(document).ready(function () {
var ckbox = $('#tcagreecreateaccount');
$('#tcagreecreateaccount').on('click',function () {
if (ckbox.is(':checked')) {
$('#idofyourinputwrapper').show(); //idofyourinputwrapper is your input wrapper
} else {
$('#idofyourinputwrapper').hide();
}
});
});
});
wrap your two inputs with a div like below.
<div id="idofyourinputwrapper">
Hope this helps :)
edited 1 hour ago
answered 3 hours ago
Prathap GunasekaranPrathap Gunasekaran
1,302417
1,302417
i tried but not event working....
– prabhakaran7
3 hours ago
Event?? what that mean? The above code do, remove required field and when you click checkbox it will show and hide the below field. Please update your code
– Prathap Gunasekaran
3 hours ago
i added this not working <div id="idofyourinputwrapper"> <div class="field skype required"> <label class="label" for="skype2"> <span><?= $block->escapeHtml(__('Check now')) ?></span> </label> <div class="control"> <input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}"> </div> </div> </div>
– prabhakaran7
3 hours ago
i set is required:false
– prabhakaran7
3 hours ago
Have you added script ??
– Prathap Gunasekaran
3 hours ago
|
show 11 more comments
i tried but not event working....
– prabhakaran7
3 hours ago
Event?? what that mean? The above code do, remove required field and when you click checkbox it will show and hide the below field. Please update your code
– Prathap Gunasekaran
3 hours ago
i added this not working <div id="idofyourinputwrapper"> <div class="field skype required"> <label class="label" for="skype2"> <span><?= $block->escapeHtml(__('Check now')) ?></span> </label> <div class="control"> <input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}"> </div> </div> </div>
– prabhakaran7
3 hours ago
i set is required:false
– prabhakaran7
3 hours ago
Have you added script ??
– Prathap Gunasekaran
3 hours ago
i tried but not event working....
– prabhakaran7
3 hours ago
i tried but not event working....
– prabhakaran7
3 hours ago
Event?? what that mean? The above code do, remove required field and when you click checkbox it will show and hide the below field. Please update your code
– Prathap Gunasekaran
3 hours ago
Event?? what that mean? The above code do, remove required field and when you click checkbox it will show and hide the below field. Please update your code
– Prathap Gunasekaran
3 hours ago
i added this not working <div id="idofyourinputwrapper"> <div class="field skype required"> <label class="label" for="skype2"> <span><?= $block->escapeHtml(__('Check now')) ?></span> </label> <div class="control"> <input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}"> </div> </div> </div>
– prabhakaran7
3 hours ago
i added this not working <div id="idofyourinputwrapper"> <div class="field skype required"> <label class="label" for="skype2"> <span><?= $block->escapeHtml(__('Check now')) ?></span> </label> <div class="control"> <input type="text" name="skype2" id="skype22" value="" title="<?= $block->escapeHtmlAttr(__('Check now')) ?>" class="input-text" data-validate="{required:false}"> </div> </div> </div>
– prabhakaran7
3 hours ago
i set is required:false
– prabhakaran7
3 hours ago
i set is required:false
– prabhakaran7
3 hours ago
Have you added script ??
– Prathap Gunasekaran
3 hours ago
Have you added script ??
– Prathap Gunasekaran
3 hours ago
|
show 11 more comments
Firstly remove required from your checkbox and other two attributes.
Both attributes depending on checkbox click will be hidden by default (can do with CSS or JS).
On checkbox click, you can use jQuery to display both attributes.
done.........................
– prabhakaran7
31 mins ago
add a comment |
Firstly remove required from your checkbox and other two attributes.
Both attributes depending on checkbox click will be hidden by default (can do with CSS or JS).
On checkbox click, you can use jQuery to display both attributes.
done.........................
– prabhakaran7
31 mins ago
add a comment |
Firstly remove required from your checkbox and other two attributes.
Both attributes depending on checkbox click will be hidden by default (can do with CSS or JS).
On checkbox click, you can use jQuery to display both attributes.
Firstly remove required from your checkbox and other two attributes.
Both attributes depending on checkbox click will be hidden by default (can do with CSS or JS).
On checkbox click, you can use jQuery to display both attributes.
answered 4 hours ago
Amrit Pal SinghAmrit Pal Singh
781523
781523
done.........................
– prabhakaran7
31 mins ago
add a comment |
done.........................
– prabhakaran7
31 mins ago
done.........................
– prabhakaran7
31 mins ago
done.........................
– prabhakaran7
31 mins ago
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266159%2fhow-to-add-custom-checkbox-with-event-in-customer-registration-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
hm wait..........
– prabhakaran7
3 hours ago