Wicket calling js based on condition - javascript

I am trying to solve the following problem, off course unsuccessfully.
On my website I have form with DataTextField where user put date.
When user confirms (AjaxButton) the form I need to find out the date and if the date is from "future" I need to call javascript(confirmation dialog).
The question is How to call js when condition is done?
I am helpless and appraise some help.

Without any code fragments it's hard to tell you what goes wrong but basically:
onSubmit(AjaxRequestTarget target)
{
target.appendJavaScript("if(confirm('Date in future!')){}; return;");
}

Related

Passing script variable to the next page

I've got spinning wheel script that I'm trying to use to give away small prizes to visitors when they login to a website. The wheel animation all works great and the script puts the 'result' into a variable and displays that in a modal on the page. You can see it in action here...
https://ezclix.club/wheel2/index.asp
The result value shows up as the third line in the modal, inserted t oa span #displayprice.
var response = "";
response += selectedSegment.winResult;
$("#displayprice").html(response);
I just need to get that value to the next page, so I can actually 'award' the prize, but so far nothing I've tried seems to work.
I tried setting a cookie but that doesn't make it through.
setCookie("Prize", response, 1)
I've tried adding a form to the modal, and using jquery to update an input with the result value, but that doesn't want to work either.
$('input[id=passprize]').val(response);
$('input[name=passprize]').val(response);
I've tried adding a whole new form input, but no go there as well.
I don't do much with jquery and my experience is mostly limited to minor edits to existing scripts, but the edits above are all things I've done in the past, so I'm stumped.
Any ideas at all much appreciated!
Here's the full function...
function alertWinResult(selectedSegment) {
jQuery(".spin_pin").rotate(0);
$("#spinWinResult").text(globlefuncgeneral.gameover_text);
$(".power_controls").hide();
var response = "";
response += selectedSegment.winResult;
$("#displayprice").html(response);
// My variousattempts...
setCookie("Prize", response, 1)
$('input[id=passprize]').val(response);
$('input[name=passprize]').val(response);
}
You can use url parameter to pass the prize when redirect to next page url/action?prize={response}
enter code here
//Using cookie
setCookie("Variable", response, value)
//using url redirect
next page url/action?Variable=value
I'm not sure how or why, but the form part of this is now working. The snippet above is populating the field so that's getting passed to the next page.
I left it for a while, came back a few hours and it worked without any further changes. So guessing there's some caching going on maybe?
Either way, sorry to waste people's time on this and thanks for your suggestions.

Is it possible to manually edit data after a dropdown auto-populates the field?

I am the opposite of a code monkey, so please forgive me if this is a simple solution. I have searched and searched and though I've found possible code examples, cannot find any information on how to fix the issue.
I've created a form-fillable PDF. I have fields that calculate based on inputs. I have a dropdown box that auto-populates some of the numbers (to add to the manual inputs). All of these work great!
I thought I would get fancy and further fill some of my data in the form. This is where the problems get funky.
I am setting the fields as shown, but those numbers can no longer be modified afterward.
this.getField("RanksPsy").value = psy;
this.getField("RanksBlade").value = blde;
this.getField("RanksBrawl").value = brwl;
this.getField("RanksCou").value = cou;
this.getField("RanksDip").value = dip;
I have buttons to increase/decrease the Ranks... fields, but the dropdown locks them and I'd like to avoid that if possible.
Is there another way to set those fields without using this.getField?
Thank you.
If I'm honest, I didn't understand the question well 😅
I don't recognize the getField function, so I decided to google it and found a RAD PDF documentation, so I'm assuming that's the library you're using to do this.
As that documentation states,
getFunction gets the first PDF form field object in the loaded
PdfWebControl document with a given name.
And this is the example provided, it may help.
var field = myApi.getField("Test Name");
if(field) {
//set its name to "New Name"
field.setProperties( {"name" : "New Name"} );
}
The solution to this is to put the script as an 'on blur' event rather than a keystroke event. It writes the data and then leaves it alone, which is exactly what I was looking for.

set default values for fields when using skip logic in qualtrics

If a user selects '1' for Yes, I know how to easily skip the next 5 questions in Qualtrics.
But, I don't just want to apply a logical skip and leave the fields blank. I'd like to autopopulate the skipped fields with a custom value (in my case, a -10). How can I do that?
I see information on display logic...or piping in values...but these aren't what I want. Any help is greatly appreciated.
EDIT: I am starting to suspect I will need to learn Javascript to do this...
There is no way to achieve this natively, instead what you want to do is use JavaScript to hide the questions when your condition is met, select the appropriate answer, and click the next button automatically. Here is a basic template for this:
Qualtrics.SurveyEngine.addOnload(function()
{
var skip = "${e://Field/skip}"; //Set a variable using piped text that can be used to determine whether or not to skip
if(skip == 1){
this.getQuestionContainer().hide(); //Hide the question
//This section is used to set the answer value. Use the Qualtrics JS Question API to determine what you need.
this.setChoiceValueByRecodeValue(1,true);
//End answer setting
$('NextButton').click(); //Click the next button
}
});
Here is a very basic preview using this example.

Sharepoint: How to get date value from DateTimeField on custom form via Javascript/JQuery?

I've searched the web for a while, but I couldn't find a simple answer to my question. So, I've got a Sharepoint List, with Date and Time type, and I created a custom form for adding new element's. On the form, I created a DateTimeField just like that:
<SharePoint:DateTimeField runat="server" id="ff_Order_Asset_DeliveryDate" FieldName="DeliveryDate" />
And everything works just fine. Now i would like to add a validation, becasue selected date can't be in the past, so i need to compare it do current date. I would like to do it in javascript using PreSaveAction, but the problem is, i have no clue how to get date value from my control. I've tried something like this:
var dateSelected = document.getElementById("<%=ff_Order_Asset_DeliveryDate.ClientID%>");
var dateFromSelection = new Date(dateSelected.value);
var dateNow = new Date();
if (dateFromSelection < dateNow)
doSomething();
But of course it doesn't work. Please enlighten me how could i manage to do that? I will be very gratefull!
------------------------------- ANSWER --------------------------------------
If someone care: it seemed that only thing i should have done, is use this jQuery syntax:
var dateSelected = $('input[id*="ff_Order_dFAsset_DeliveryDate"]');
beacuse as Mark Oreta said, Sharepoint added much to ID of my control.
Are you opposed to using the the column validation? If so, I suggest just validating that way.
If javascript is your only option then it's not going to be as easy as selecting the text box due to the fact that sharepoint adds a bunch of data to the id of the item when it generates the form. Based on what you've posted it looks like you've extracted the form so what I would do is wrap a span around the so that the input is generated inside the div and locate it that way.
<span id="span-dateselected">
<SharePoint:DateTimeField runat="server" id="ff_Order_Asset_DeliveryDate" FieldName="DeliveryDate" />
</span>
Then in your javascript you'll need to find the span, then the inputs:
var dateFromSelection = document.getElementById("span-dateselected").getElementsByTagName("input")[0].value;
The code snippet above makes some assumptions that might or might not be good so you might want to test that the javascript found the input properly. I suggest using Jquery to iterate through the list that's generated, but I realize that might not be an option for you.
If someone care: it seemed that only thing i should have done, is use this jQuery syntax:
var dateSelected = $('input[id*="ff_Order_dFAsset_DeliveryDate"]');
beacuse as Mark Oreta said, Sharepoint added much to ID of my control.
do not use datetime field control see url below:
http://www.entwicklungsgedanken.de/2009/08/21/do-not-use-datetimefield-when-displaying-the-date-of-your-field/
Have you tried below code?
var dateSelected = document.getElementById("ff_Order_Asset_DeliveryDate.ClientID");
without the ASp tags?

jqgrid - how do not show edit form if condition not met

Another jqgrid question. On my page i got a select drop down. If nothing is selecting and the user click to add record, the edit form should no popup. I can't seems to find how to do this in google. Here is what I have:
afterShowForm:function(formid) {
if ( ($('#listbox').val()) == "" ) {
alert('Please select an option.');
$('#'+formid, form).hide();
return false;
}
}
The above code is not working. It actually got error - form is not defined. Should I be using afterShowForm or is there a more proper way to do it.
Thanks.
Ok guys. I found a 'solution' but I am not sure if that is the best way to do it (I think it is not :) ) but it gets the job done.
Instead of using formid pass in through the function, I have view source and get the id of the edit form id. For my case the id is #editmodmy_table. So to hide the form from showing, I just use jquery to do it.
$('#editmodmy_table').hide();
Other than that, we have to get rid of the overlay that is attached to the edit form modal as well. Hiding the edit form don't hide the overlay automatically. So we have to do this:
$('.jqmOverlay').hide();
Hope this helps someone.
Please post a better solution to this if any. Thanks.
The error in this code means that the variable 'form' is not defined.
If I understand this correctly that variable is not needed.
To find the form and hide it you could try something like this instead:
$('form#'+formid).hide();

Categories