How to add custom checkbox with event in customer registration Magento 2?












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>









share|improve this question

























  • hm wait..........

    – prabhakaran7
    yesterday
















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>









share|improve this question

























  • hm wait..........

    – prabhakaran7
    yesterday














2












2








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>









share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







prabhakaran7

















asked yesterday









prabhakaran7prabhakaran7

1869




1869













  • hm wait..........

    – prabhakaran7
    yesterday



















  • hm wait..........

    – prabhakaran7
    yesterday

















hm wait..........

– prabhakaran7
yesterday





hm wait..........

– prabhakaran7
yesterday










2 Answers
2






active

oldest

votes


















1














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






share|improve this answer


























  • i tried but not event working....

    – prabhakaran7
    yesterday











  • 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
    yesterday











  • 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
    yesterday











  • i set is required:false

    – prabhakaran7
    yesterday











  • Have you added script ??

    – Prathap Gunasekaran
    yesterday



















0














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.






share|improve this answer
























  • done.........................

    – prabhakaran7
    yesterday











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
});


}
});














draft saved

draft discarded


















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









1














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






share|improve this answer


























  • i tried but not event working....

    – prabhakaran7
    yesterday











  • 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
    yesterday











  • 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
    yesterday











  • i set is required:false

    – prabhakaran7
    yesterday











  • Have you added script ??

    – Prathap Gunasekaran
    yesterday
















1














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






share|improve this answer


























  • i tried but not event working....

    – prabhakaran7
    yesterday











  • 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
    yesterday











  • 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
    yesterday











  • i set is required:false

    – prabhakaran7
    yesterday











  • Have you added script ??

    – Prathap Gunasekaran
    yesterday














1












1








1







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






share|improve this answer















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







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









Prathap GunasekaranPrathap Gunasekaran

1,337417




1,337417













  • i tried but not event working....

    – prabhakaran7
    yesterday











  • 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
    yesterday











  • 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
    yesterday











  • i set is required:false

    – prabhakaran7
    yesterday











  • Have you added script ??

    – Prathap Gunasekaran
    yesterday



















  • i tried but not event working....

    – prabhakaran7
    yesterday











  • 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
    yesterday











  • 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
    yesterday











  • i set is required:false

    – prabhakaran7
    yesterday











  • Have you added script ??

    – Prathap Gunasekaran
    yesterday

















i tried but not event working....

– prabhakaran7
yesterday





i tried but not event working....

– prabhakaran7
yesterday













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
yesterday





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
yesterday













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
yesterday





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
yesterday













i set is required:false

– prabhakaran7
yesterday





i set is required:false

– prabhakaran7
yesterday













Have you added script ??

– Prathap Gunasekaran
yesterday





Have you added script ??

– Prathap Gunasekaran
yesterday













0














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.






share|improve this answer
























  • done.........................

    – prabhakaran7
    yesterday
















0














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.






share|improve this answer
























  • done.........................

    – prabhakaran7
    yesterday














0












0








0







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Amrit Pal SinghAmrit Pal Singh

781523




781523













  • done.........................

    – prabhakaran7
    yesterday



















  • done.........................

    – prabhakaran7
    yesterday

















done.........................

– prabhakaran7
yesterday





done.........................

– prabhakaran7
yesterday


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?