Lotus-Notes: Reset Radiogroup via Javascript - javascript

I'm currently working on a Lotus Notes solution. We're just using Web forms so client side operations are done via Javascript.
What I want to accomplish is to reset a Group of Radio Buttons. There are 3 possibilities and I want to choose none. (A 'none of them' possibility would be preferable, I know but we are required to reset them)
I currently use:
//Unchecks a single group of Radio Buttons
//groupname - the name attribute of the group which selection needs to be unchecked
function clearRadioButtonGroup(groupName) {
for(i=0;i<document.forms[0].elements[groupName].length;i++) {
document.forms[0].elements[groupName][i].checked = false;
}
}
The problem with this routine is, the Radiogroup gets reset, but on a form submit the old value gets submitted. Any suggestions?

What version of Domino are you using? Since 7.x (I think) a %%Surrogate field gets generated as a hidden field in your HTML that you'll be able to reset, so after deselecting all of the radio button options, you can then clear out the %%Surrogate field and you should then avoid having to select a "None of the above" option.
Matt

The problem is that clearing the radio buttons make no information about them appear in the submitted form data, and Domino seems to interpret that as no change to the field rather than clear the field.
I haven't found any solution to this I really like, but I can think of two options:
Change the radio buttons to include a no choice option.
The alternative is a bit clumpsy:
Add an editable field to the form to use as a flag, hide it from the web browser with css.
Have clearRadioButtonGroup also set the flag field to something.
Have the onChange event of the radio buttons clear the flag field.
In a WebQueryOpen agent, set the radio buttons field to empty if the flag field is non-empty.
Another alternative could be to uses some clever javascript/css trick to hide the no choice option and have clearRadioButtonGroup simply set that choice.

Are you certain that the old value is actually being submitted? Perhaps it just isn't being updated (erased) in the NotesDocument you're editing? Just a hunch...
BTW, you can download a program called Fiddler that will let you inspect the HTTP POSTs, and you can confirm that the POST data doesn't contain any values for that radio button group. That might help narrow down the problem.

Put the following pass thru HTML code on your form:
<input type="hidden" name="FieldName" id="FieldID" value="">
(FieldName and FieldID are the name and id of your radio field on the form)
When you reset your radio through Javascript and submit your document, the field will be reset to blank.

Related

How to detect changes in the asp panel through javascript?

I have many controls(like texbox,telerik grid, dropdown and radio button) on one asp panel.Could someone help me in detecting changes in any control of asp panel while clicking submit button.
There might be a better way of doing this, but my suggestion would be:
Create a hidden field that has a default value of "False". This hidden field will tell us if the form has changed or not.
Then assigning any editable control the JavaScript OnChange event.
The OnChange event should call a simple method that sets the value of the hidden field to "True".
For example with jQuery it would be:
function FormChanged() {
$(".hiddenField").val("True");
}
Then when you submit you will be able to access the value of the hidden field to know wether the form has benn changed or not.

Need to find where my radio option CHECKED value gets changed

Is there way that i could identify where a radio option value gets changed, either thru watch expression on firebug or inspect element ?
i am remote debugging a website and there are 4 radion buttons in the website. We set the CHECKED property for my 4th option as true, it gets checked. But after a sometime(1 sec) my first option gets selected automatically. There are too many javascript code involved and i am not sure where to check.
So is there any way i can do a debug-BREAK when a watch expression fires or any other way to debug this?
You can do this using jquery:
$('input[type=radio][name="inputName"]').on('change',function(){
//#myForm is the id of the form that the radio box in
alert($('input[name="inputName"]:checked', '#myForm').val());
});
This will alert the new value of the radio box when changed JsFiddle

Form validation in javascript when drop down dependency is involved

I have used ng-disabled for my form validation for ADD button.
i.e. ng-disabled="conditionForm.$invalid". But , My form contains two text boxes which are hidden at first , and when a type is selected from drop down , only the respective Text box div should be visible. The Problem i'm facing is ,when the above ng-disabled validation is used , the ADD button is still disabled when one of the text box is selected and an input is provided. After the second input is also selected from the drop-down , then the ADD button is getting enabled.
Can you please provide me with an alternate validation , where the ADD button can get enabled every time a value is selected from drop down and a valid input is provided.
If you're ng-disabled is on a form being valid or invalid it sounds like those may have required inputs set. If that is case look at using ng-required so you can explicitly set required based on expression. You can then control when the form is valid.
The exact answer: Answer

Javascript Disabling Multiple field objects onchange

I was using the following script to disable multiple field objects when one field was selected, I have changed the fields so that they no longer have a default value of zero but can have varying values:
JS
function disablefield(fieldObj)
{
var fields = new Array('Seat_1200', 'Seat_1230', 'Seat_100','Seat_130','Seat_500','Seat_530','Seat_600','Seat_630','Seat_700','Seat_730','Seat_800','Seat_830');
for(var i=0; i<fields.length; i++)
{
fieldObj.form[fields[i]].disabled = (fieldObj.value!=0 && fieldObj.name!=fields[i]);
}
return;
}
Can anyone suggest a way to detect the current value of the fields seat_xxxx (which are loaded dynamically) integrate it into the above script then disable the all fields when the value one changes. Or alternatively if the field is de-selected i.e. the user changes his mind and selects another option, then the field is set to zero automatically to satisfy the above script re-enabling all the selection options.
In response to the problem from the author I have a new code set.
I would use a Jquery button set to represent all the tables you have. Then selectively disable them based on the result. Below is a fiddle
http://jsfiddle.net/05cpss80/
Buttonsets are really just classed checkboxes but they give you what you need.
<input type="checkbox" id="check1"><label for="check1">Table1</label>
As such you can add additional classes to them to stop them from "checking"
$('#check2').attr("disabled", "disabled");
I would recommend you add some css to make it more obvious, but try the fiddle. Click 2, then the button and it will no longer work. (Thus when they make a selection you call disable on whatever tables you need)

Clearing a jQuery Form

I have been doing some research on a good way to clear a jQuery form.
I have a couple of ideas but I want to know if someone has a better way.
I know about using reset, but sometimes it is necessary to set a field back to a particular value that may not be accomplished by reset. (ie. if a form starts with some pre-filled data and you want to clear it)
I have read some discussion here: Resetting a multi-stage form with jQuery
But I have another idea that I will post as an answer. Please let me know what you think and if you have a better solution.
More Information:
For example I have an address form. It has a couple of inputs, selects, radios, etc. along with a copy into new button and a clear button. By default I want to have this particular radio selected to option 1.
<div id = "AddressList">
<div class = "Address">
<input type="radio"/> --obviously with some options here
<button>copy into new</button>
</div>
</div>
The user selected option two and clicks copy into new. So I say something like on the click of the click of the copy into new:
$("#addressList").append($(this).closest("#Address").html());
In the second address the secon radio button is selected. The user selects the third radio button. At this point clicking the reset button would reset the input back to option two not option one.
My solution would be to add the attribute called clear.
Then say $([clear]).val($(this).atrr('clear'))

Categories