In Variants » *** » Content the button for adding new content is not showing up. In addition the edit content appears disabled. Can these functions be turned off? I may have done so inadvertently.

Comments

merlinofchaos’s picture

These functions cannot be turned off. The buttons can sometimes disappear if something on the page causes javascript to crash before Panels javascript creates the buttons. Check your javascript console and see if there's a javascript error on the page?

kiernan’s picture

Issue tags: +Webforms

The JS console led me to the calender field in Webforms. When enabled the buttons did not work. Once I removed the calender fields the buttons came back on.

merlinofchaos’s picture

You should move this issue to the module providing the javascript, and provide the actual error. Maybe if we're lucky it'll be an easy fix.

kiernan’s picture

I have not moved a issue before. Do I just change the Issue settings?

merlinofchaos’s picture

Yes.

kiernan’s picture

Project: Panels » Webform
Version: 7.x-3.x-dev » 7.x-3.9
Component: Panel pages » Miscellaneous

I am moving this from Panels for review. I managed to isolate the problem but due not know how solve the issue for others.

quicksketch’s picture

Title: Adding New Content in varients not working » Webform Data Popup calendar causes JS error when adding to a Panel
Category: support » bug

Could you describe the error you're getting in the JavaScript console? My guess is Webform doesn't have all the settings it needs to render the calendar correctly. Unfortunately I don't regularly use Panels, I'm not very likely to look into this myself.

kiernan’s picture

Here is what I got when recreated. I issue is present when in the edit panel UI.

Error: $calendar[0] is undefined
Source File: http://XXXXX/sites/all/modules/webform/js/webform.js?ll3m9y
Line: 21

/**
* JavaScript behaviors for the front-end display of webforms.
*/

(function ($) {

Drupal.behaviors.webform = Drupal.behaviors.webform || {};

Drupal.behaviors.webform.attach = function(context) {
// Calendar datepicker behavior.
Drupal.webform.datepicker(context);
};

Drupal.webform = Drupal.webform || {};

Drupal.webform.datepicker = function(context) {
$('div.webform-datepicker').each(function() {
var $webformDatepicker = $(this);
var $calendar = $webformDatepicker.find('input.webform-calendar');
var startYear = $calendar[0].className.replace(/.*webform-calendar-start-(\d+).*/, '$1');
var endYear = $calendar[0].className.replace(/.*webform-calendar-end-(\d+).*/, '$1');
var firstDay = $calendar[0].className.replace(/.*webform-calendar-day-(\d).*/, '$1');

// Ensure that start comes before end for datepicker.
if (startYear > endYear) {
var greaterYear = startYear;
startYear = endYear;
endYear = greaterYear;
}

// Set up the jQuery datepicker element.
$calendar.datepicker({
dateFormat: 'yy-mm-dd',
yearRange: startYear + ':' + endYear,
firstDay: parseInt(firstDay),
onSelect: function(dateText, inst) {
var date = dateText.split('-');
$webformDatepicker.find('select.year, input.year').val(+date[0]);
$webformDatepicker.find('select.month').val(+date[1]);
$webformDatepicker.find('select.day').val(+date[2]);
},
beforeShow: function(input, inst) {
// Get the select list values.
var year = $webformDatepicker.find('select.year, input.year').val();
var month = $webformDatepicker.find('select.month').val();
var day = $webformDatepicker.find('select.day').val();

// If empty, default to the current year/month/day in the popup.
var today = new Date();
year = year ? year : today.getFullYear();
month = month ? month : today.getMonth() + 1;
day = day ? day : today.getDate();

// Make sure that the default year fits in the available options.
year = (year < startYear || year > endYear) ? startYear : year;

// jQuery UI Datepicker will read the input field and base its date off
// of that, even though in our case the input field is a button.
$(input).val(year + '-' + month + '-' + day);
}
});

// Prevent the calendar button from submitting the form.
$calendar.click(function(event) {
$(this).focus();
event.preventDefault();
});
});
}

})(jQuery);

quicksketch’s picture

Could you try adding the following?

Right after:
var $calendar = $webformDatepicker.find('input.webform-calendar');

Add this:

if ($calendar.length == 0) {
  return;
}

If that works I'd be happy to include this change in the next version of Webform.

merlinofchaos’s picture

CTools is using a similar method to Core in D7 for transmitting ajax and settings during ajax requests, and it actually works (more or less) with wysiwyg.module.

kiernan’s picture

I added the code and the add content button is there. I added content. The fix look good.

Thanks

quicksketch’s picture

@merlinofchaos: Yeah the odd thing is this problem would indicate that the JavaScript is all loading fine but something in the markup is wrong. Since the JS executes but it doesn't find the markup it expects. The suggestion I made in #9 essentially is a "bail out if the markup isn't what you expect". So whatever CTools is doing with JS is probably fine, but the markup being pulled in is unexpected.

kiernan’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

duntuk’s picture

#9 doesn't work, but this does; put right before the var's:

if(!window.console){ window.console = {log:function(){}}; }

so it looks like this

Drupal.webform.datepicker = function(context) {
  $('div.webform-datepicker').each(function() {
	  
    if(!window.console){ window.console = {log:function(){}}; }
    var $webformDatepicker = $(this);
    var $calendar = $webformDatepicker.find('input.webform-calendar');
    var startDate = $calendar[0].className.replace(/.*webform-calendar-start-(\d{4}-\d{2}-\d{2}).*/, '$1').split('-');
    var endDate = $calendar[0].className.replace(/.*webform-calendar-end-(\d{4}-\d{2}-\d{2}).*/, '$1').split('-');
    var firstDay = $calendar[0].className.replace(/.*webform-calendar-day-(\d).*/, '$1');
...

POW!

theodorosploumis’s picture

#9 works for me too. Thanks!

majdi’s picture

#9 Works fine for me

fonant’s picture

#9 already present in the code, but popup still breaks with

$calendar.datepicker is not a function

Webform 6.x-3.19
Date Popup 6.x-2.9

Disabling console logging as per #15 makes no difference.

fonant’s picture

Arghh! My mistake: I hadn't installed the jQuery UI module.