How to hide / show yui.calendar.DatePicker in wicket - javascript

I've run in to a problem I hope you guys can help me with.
I'm using a DateTextField with a DatePicker (from yui.calendar), they are both added to a WebMarkupContainer with OutputMarkupId and OutputMarkupPlaceholderTag set to true.
I want to be able to set the visibility of the container, but when I set it from true to false to true, the datepicker is no longer visible (I'm guessing it has to do with it not beeing mentioned in the HTML(?)) and I have to reload the entire page (and loose the input data) to get the DatePicker visible again. There is no problem with the DateTextField. Is there any good way to work around this?
JAVA:
invoiceDateFromField = new DateTextField("invoiceDateFromField", new PropertyModel(this, "invoiceDateFrom"), new PatternDateConverter("yyyy-MM-dd", true));
invoiceDateFromField.setOutputMarkupPlaceholderTag(true);
invoiceDateFromField.add(new DatePicker());
containsAllContainer.add(invoiceDateFromField);
AjaxLink onClick:
containsAllContainer.setVisible(!containsAllContainer.isVisible());
target.add(containsAllContainer);//Edit
I tried to remove the DatePicker from invoiceDateFromField, and then add a new one when the container is set to visible, but this did not seem to work either.
Thanks!
Olle

YUI will lose its connection to the DOM element when you set it visible=false in Wicket (because the node is removed from the DOM). So when you add it back to the page, your instance of YUI calendar no longer has any associated field in the DOM. You need to be sure to update your reference with a new instance of calendar every time you re-render the DateTextField with Wicket

Related

window.onSelection() in Template.myTemplate.onRenderd() in blaze

I have a template (blogContent.html) which loads the text on the page using helpers in (blogContent.js). Once the page has loaded, I'm trying to select some text on blogContent.html and highlight it.
To get the selected text, I'm trying to do something like this
Template.blogContent.onRendered(function(){
if (window.onSelection) {
var selectedText = window.onSelection().toString();
console.log(selectedText);
}
});
However, I'm encountering two issues with it.
1. The if block is always executed when the page is loaded and never afterwards i.e. not when I selected some text.
2. Because of (1), console.log outputs a null string on client console only once when the page loads and nothing heppens afterwards.
Any pointers are much appreciated. I'm new to webdev and meteor. Thanks a lot.
window.onSelection is not a valid function or property. You may be thinking of window.getSelection().
Meteor doesn't re-render the template unless the data inside of it changes, so the onRendered function won't be called.
What you want here is plain old jQuery -- see this question for how to create a listener for text selection.

Delete a DOM element and its associated jquery plugin and data

First, I'm using a jquery plugin on an element, lets say $('#myElement').usePlugin();.
Second, I want to destroy the original element and any plugin variables etc that may still exist in JS.
Third, create a new #myElement and redo $('#myElement').usePlugin();.
I'm having trouble with step #2. When I do $('#myElement').remove(), there is residual strange behavior when I recreate the element and instantiate the plugin.
FYI: this is the plugin I'm having trouble with: http://mindmup.github.io/editable-table/. If I create a table, make it editable, everything works fine.
But then if I delete the table, recreate the table, make it editable, I get strange behavior where fields are editable, but when I hit "enter", the value does not save and I get this error Uncaught TypeError: Cannot read property 'trigger' of undefined.
I would modify this line in the plugin:
https://github.com/mindmup/editable-table/blob/master/mindmup-editabletable.js#L115
to:
$(window).on('resize.mindmup', function () {
Now, when you want to remove that event, remove it by namespace.
$(window).off("resize.mindmup");
Continue removing and re-creating the table, then use the above line to remove the window resize event before re-initializing the plugin.

jquery selectize error: issue with adding new select fields and combox-ifying them

I am trying to the Selectize library so I can have a comboboxes on my form.
So my form has a way to dynamically add more dropdowns (that i want to be comboboxes), so whenever the user adds a new dropdown, I want to apply Selectize combobox to it. So within my function that adds the new dropdown, after I have appended it, I use the following code:
$('select').each(function() {
if (!$(this).is('selectized')) {
$(this).selectize({
create: true,
sortField: 'text'
});
}
});
I thought that this would only apply it to dropdowns that do not already have Selectized combo box applied to it, but something is going wrong. Basically it is applying it to new comboboxes but something strange is going on with the existing ones. It's adding some kind of blank dropdown each time.
I tried to look around but I cannot find an "official" solution for combobox-ifying a newly added select fields. I don't know if it's an issue with how I am applying it, or if it's some kind of weird conflict with twitter bootstrap or jquery-ui or jquery itself (I included all of those in the fiddle)
Anyways, here is a link where you can see this issue in action:
http://jsfiddle.net/Qz7Ar/2/
Does anybody have experience with this or know what's going on here?
edit:
I also made a fork removing jquery-ui and bootstrap, so it's just jquery (required for Selectize) and Serialze, and the issue is still happening:
http://jsfiddle.net/Wxxub/1/
Okay well I figured out how to fix it..
If I add an id attrib to the new element and target by that instead, it works. Here is another fork demonstrating it:
http://jsfiddle.net/Wg7J6/1/
I can't find anywhere in the Selectize doc that it's necessary (I could be blind though!) that the select field must have an id or if it would work without one but i'm just doing it wrong or what, though.

jQuery UI datetimepicker bound to wrong input after DOM element removed

Here's something to bake everyone's noodle. I have a form on a website. You can look at it: My Website. Click book me and select a certain number of days at the top right. Manually remove a few of the form lines from the form using the '-' button. Then try to use the first input on the first line. It's linked to the wrong input. All the inputs have unique ID attributes, and I rebind datetimepicker class after a line is removed. Anyone have the foggiest idea why the datetimepicker pointing the the wrong object? Ironically enough, the timepicker portion, which is not from jQuery UI proper, still points to the correct input, it would seem. It seems that when you delete lines of a lower number, the lines of a higher number are moved and renamed, but the date portion f the datetime picker is still pointing the the line number that it was originally bound to, if that makes any sense.
Help is appreciated because this one has me stumped. I've tried manually releasing the datepicker objects before I remove the form lines, but nothing seems to help.
Thanks
Edit: Is there a way to completely destroy the instances of the datepicker that are bound to the input elements before I remove them?
Edit: Alright, I just had a realization. I am destroying the datepickers on the lines I'm removing, but not the lines that remain, so I'm going to work on this for a minute and see if destroying the datepickers completely when i rebuild the form helps.
No time to analyse all that code but could possible help to call $(elem).datetimepicker('destroy') when you remove a control before any rebinding.
In setAlts()
try removing var fields = $('.date').get();
and just doing:
$('.date').each(function() {
$(this).datetimepicker('destroy'); // From Marcell
$(this).datetimepicker({
minDate: now,
timeFormat: "h:mm tt",
stepMinute: 15,
});
});
If you remove dateCheck() all should be fine.
I assume below is what you are intending with dateCheck() though.
Ok in dateCheck()
change:
target.siblings('.date').datetimepicker('setDate', dateMin);
to:
target.next('.date').datetimepicker('minDate', dateMin);
Alright, so to answer the question: It seems obvious in retrospect, but the datetimepicker addon which is coded in a slightly different, and probably less efficient, manner was throwing me off the trail. At any rate, I'll try to explain what was happening in a clear fashion.
The datepicker object binds to the id of the element when it is created, and it keeps that id until it is destroyed. And apparently, attempting to bind a new datepicker object does nothing if there is already a datepicker object present.
To rememdy the problem, in the setAlts() method, I simply destroyed every single datepicker object, and recreated it. Pretty simple, but it was confusing the hell out of me.
And thanks for setting me on the right path. Otherwise I'd have probably had a chimpout and started smearing my poo on the walls.

Change jquery ui datepicker programmatically

I've got a jquery ui datepicker on my page. It's linked to a span not an input. It's currently tweeked to select a week at a time. I've also got two buttons on my page 'Previous Week' and 'Next Week'. I want the buttons to control what's selected by the datepicker. (ie jump forward / backward by one week when pressed).
I'm not sure how to grab the datepicker so I can mess with it (or what I actually mess with - is there a real 'object' there, or is it a just a load of css / html component like 'ui-datepicker-current-day' etc).
there is a real object you can hold a reference to.
example:
var datePicker = $("#id").datepicker({firstDay: 1});
to know what you can do with it, check:
http://jqueryui.com/demos/datepicker/

Categories