Hide/ Unhide sections on button click in elementor form - wordpress

I am creating a form in elementor using the form, I have a radio button by clicking it, some of the fields should unhide. How do I achieve it?
Below is the screenshot

The first thing to do is to correctly name the IDs in your elementor form.
Please name radio button's ID with same_as_shipping_address.
And in CONTENT -> Options please write this:
Same as shipping address|same_as_shipping_address
Ohters options 1|other_option_1 /* You have to write your own option */
Elementor will then create an input that will have a selector:
input[name="form_fields[same_as_shipping_address]"]
Then for all the elements to hide when the radio button is selected, give them an ID with _show_if_same_as_shipping_address at the end.
For example for the phone (if it has to be hidden) the ID will be phone_number_show_if_same_as_shipping_address
Elementor will then create a div with it as a class:
.elementor-field-group-phone_number_show_if_same_as_shipping_address
Now the goal is to check each change of input[name="form_fields[same_as_shipping_address]"] and display the fields that have like an ID with _show_if_same_as_shipping_address at the end.
We are going to use a jQuery script to do this.
If you don't have child theme, create one and use this jQuery code:
jQuery(document).ready(function ($) {
var radio = $('input[name="form_fields[same_as_shipping_address');
var toToggle = $("div[class*=_show_if_same_as_shipping_address]");
/* By default */
onRadioChange();
/* Function triggered when the visitor changes the status of the sending address */
radio.on("change", function (e) {
onRadioChange();
});
/* Action to be carried out */
function onRadioChange() {
if (getRadioVal()=== "same_as_shipping_address") {
toToggle.css('display', 'flex');
}
else {
toToggle.css('display', 'none');
}
}
function getRadioVal() {
return $('input[name="form_fields[same_as_shipping_address:checked').val();
}
});

Related

How do you add a custom button to the Elementor Text Editor widget toolbar?

I'm trying to add a custom button into the Elementor text widget toolbar next to other buttons like Bold, Italic, Underline etc. It seems that the ability to customize the instance using PHP may be disabled but that it is possible to do so using JavaScript instead.
I can get back the view by using the following code but I'm unable to get back the editor instance.
elementor.hooks.addAction( 'panel/open_editor/widget/text-editor', function( panel, model, view ) {}
I've tried the following suggestions but none seem to return anything after that.
// get active instances of the editor
let editor = tinymce.activeEditor;
var editor = elementor.editors.get(0).getEditModel().get('editor');
var activeEditor = view.getOption('editor');
The rest of the suggested code after getting the editor instance is as follows but I don't get this far.
// add a button to the editor buttons
editor.addButton('tooltip', {
text: 'tooltip',
icon: false,
onclick: (editor) => {
tooltipCallback(editor);
}
});
// the button now becomes
let button=editor.buttons['tooltip'];
// find the buttongroup in the toolbar found in the panel of the theme
let bg=editor.theme.panel.find('toolbar buttongroup')[0];
// without this, the buttons look weird after that
bg._lastRepaintRect=bg._layoutRect;
// append the button to the group
bg.append(button);

Divi : Limit Click Times Button

I'm trying to limits the times click on button in divi theme in wordpress but don't know how and I need help. Thank you.
You don't need Divi for this, just add a simple javascript at your code to track the clicks.
Supposing that you are using jQuery, here is the code.
var clicks = 0;
var maxClicks = 3; // set the maximum time to be clicked
var elementClassSelector = '.your-class-button';
$(elementClassSelector).on('click', function(e){
// prevent the event if we already have enought clicks
if (clicks >= maxClicks) {
e.preventDefault();
} else {
clicks++ // increase the number of clicks
}
})
Here is a link how to add a custom javascript using Divi.
Here is a link to help you add javascript or CSS in any theme.

how to use page scroll to id plugin on page template in wordpress?

I have homepage which is created by using multiple small template pages in wordpress. I have set menus on it . now i want to go on particular section/ template using menu. like if i press contact menu button then it should go smoothly downwards of homepage where the contact template has been called. I am using "Page scroll to id" plugin of wordpress but its not working. I have also seen that this plugin work when the page is created by dashoard page. Please help me , how can i navigate to my template page/section using this plugin. If any other plugin is there , please tell me about it . i will try to use that too.
Thanks
To create smooth scroll on link click follow the below steps :
Step 1: Add section ids in menu href including #section1 from admin section Appearance >> Menu .
Step 2: Create section or div with id name section1.
<div id="section1"></div>
Step 3: Paste the below code under your custom js file.
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
I hope it will helps you.

In Meteor can I capture or pass the link/anchor text in the event when user clicks a link?

I am trying to set a Session variable to the text that a user clicks on when they click a link. For example if the link is The Link.
I would like to Session.set('clickedLink', <<The Link>>); but with "The Link" obviously replaced with the text string that the user has clicked on.
Is this possible? Am I going about this all wrong?
I figured I might be able to use something like:
Template.SingleQuote.events({
"click .link": function (event) {
Session.set("currentPageName", event.a.text);
}
});
Use event.target.text.
Template.SingleQuote.events({
'click .link'(event) {
Session.set('currentPageName', event.target.text);
}
});
Edit:
Instead of what has been posted, it has been suggested by reviewers that I update this answer to make use of the following syntax:
'click .link': function(event) { /* ... */ }
Both of these are perfectly valid syntax for a Meteor Template Event, use whichever you feel most comfortable with.

Dynamically add textareas into form in meteor

I want to insert textarea's into a form in meteor. This is the template I currently have:
template(name="guide_create")
.format-properly
form.form-horizontal(id="guideForm" method="POST" action="/create-guide")
.form-group
label.col-sm-2.control-label(for="title") Title
.col-sm-10
input.form-control(name="title" id="title")
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
label
input(name="is_public" type="checkbox")
p Make your guide public
.form-group
label.col-sm-2.control-label(for="cards") Cards
.col-sm-10
input.form-control(name="cards" id="cards")
center
button.btn.btn-primary#add-section(style="margin-bottom: 15px;") New Section
each sections
+section
template(name="section")
textarea.new-section(type="text" uniqid=uniqid)
button.remove-section Remove
The first template, guide_create, has the form and the second template section includes the textarea. This is how I currently add my textarea's dynamically to the page:
Template.guide_create.onCreated(function() {
Session.set('sections', []); // on page load, set this to have no inputs
});
Template.guide_create.events({
'click #add-section': function () {
var sections = Session.get('sections');
var uniqid = Math.floor(Math.random() * 100000);
sections.push({uniqid: uniqid});
Session.set('sections', sections);
}
});
Template.guide_create.helpers({
sections: function () {
return Session.get('sections'); // reactively watches the variable
}
});
I hope this is possible somehow, and I want to have these textarea's now included in my form, that when I submit the form, the content of those textarea's is also submitted. The newly created textarea is currently outside of the form and I want to change that. Any help or suggestions are highly appreciated!
I believe your sections are appearing outside of you form because they are being added in the template outside of the form group. Try moving them up into the form group, something like this?
.form-group
label.col-sm-2.control-label(for="cards") Cards
.col-sm-10
input.form-control(name="cards" id="cards")
each sections
+section
center
button.btn.btn-primary#add-section(style="margin-bottom: 15px;") New Section

Resources