1.Textbox:
While using .validateNotNumber(TextBox),the TextBox is accepting alphanumeric, which shld nt be the case, as i want to have only NAME inside a text box n nt 'abc1234', it shld accept only 'abcd'. also if the textbox handles NUMBERS only using keyuphandler, it shld only accept '1234' n not 'a1234', which is the current behaviour now. It accepts 'a1234'. meaning, the first character is nt validated properly, if we enter 'a', it does nt validate, bt if we enter'a1234', it validates correctly after the first digit, i.e, it throws err only after the i/p of 2nd character in the text box area of a NUMBER type!
function doGet()
{
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var grid = app.createGrid(11, 10).setId('maingrid');
var nameLabel = app.createLabel("Name:");
var nameTextBox = app.createTextBox().setName('name').setId('name');
var nameRequiredLabel = app.createLabel("*").setId('namerequired').setStyleAttribute("color", "red");
var requiredFieldLabel = app.createLabel("*-Required Field").setId('requiredfield').setStyleAttribute("color", "red");
grid.setWidget(0, 0, nameLabel).setWidget(0, 1, nameTextBox).setWidget(0, 2, nameRequiredLabel)
.setWidget(9, 2,requiredFieldLabel);
var invalidText=app.createClientHandler().validateNumber(nameTextBox)
.forTargets(nameTextBox).setStyleAttribute("color", "red")
.forTargets(nameRequiredLabel).setText('Please Enter a Valid Name.').setStyleAttribute("color", "red").setVisible(true);
var validText=app.createClientHandler().validateNotNumber(nameTextBox)
.forTargets(nameTextBox).setStyleAttribute("color","black")
.forTargets(nameRequiredLabel).setText('*').setStyleAttribute("color", "red").setVisible(true);
nameTextBox.addKeyUpHandler(invalidText).addKeyUpHandler(validText);
panel.add(grid);
app.add(panel);
return app;
}
Note: I used .validateInteger(TextBox) and .validateNotInteger(TextBox) also, But its too giving the same o/p as above(alphanumeric).
2.DateBox:
It shld accept only DATES format n shld nt be possible to enter any other characters after the DATE is picked.
Fr eg. If i select a DATE '14-08-2012', it shld nt accept any other characters beyond this length, like '14-08-2012abc123', literally there shld be a method to validate/restrict the field, if it's any REAL DATE format n nt just a DATE+TEXT. Accidentally, the user may enter any unwanted text in the DATE box, which we may need to avoid! We may need a '.validateDateLength()' to handle this issue!
3.Drop Down box:
in any given drop box, the option 'SELECT' will b the first option to intimate us to select the option required from the drop down list
I used .validateMatches("SELECT") and .validateNotMatches("SELECT"), to check if any option is selected by the user or not, which means i want to ensure the user has selected something from the drop down box n NT just left tht option UNSELECTED. Bt, it doesn't seem to validate the Matches.
4.Check Box,Radiobutton:
Fr these 2 controls, i just want to ensure tht the user has SELECTED any of my RADIOS or any of my CHECKBOXES, if those particular RADIO's are nt selected by the user, the control shld pass an err, saying tht 'PLZ SELECT THE RADIO/CHECK BOX OPTION TO PROCEED FURTHER'. What is the right method to do this?
Eg. script
var valid = app.createClientHandler()
.validateNumber(number)
.validateNotInteger(text)
.validateEmail(email)
.validateNotMatches(listbox, 'select')
.forTargets(submit).setEnabled(true)
.forTargets(number,text,email).setStyleAttribute("color","black")
.forTargets(numberrequired,textrequired,emailrequired).setText('*')
.setStyleAttribute("color","red").setVisible(true);
I used the above code for the 'SUBMIT' Button enable and disable concept, In this itself the ListBox is not validating correctly the 'SELECT' option.
So, basically, I want all these validation to function properly, so tht I cn make my 'SUBMIT/SAVE' ENABLED, until all my above controls are checked/validated, which ensure tht the user has entered/selected all the options properly & is in the required format to proceed to the SUBMIT page.
Hopefully, I m clear, plz dont hesitate to ask me if I m wrong/unclear somewhere!
Please guide me,
Thanks & Regards,
chocka.
I suspect addKeyPressHandler is the wrong type of handler - there is a focus style handler
But yes, the code does look more or less correct.
Related
I created a range using offset and setting the format for the range
I did that using below code
a1_range = Sheet1.getRange("D43");
var a4_range = a1_range.offset(0,6);
a4_range = a4_range.offset(0,1,15,6);
a4_range.setBackground("#e6e6e6").setBorder(true, true, true, true, true, true);
a4_range.setNumberFormat("$#");
The setNumberFormat is setting is write as I want , but the problem is when user enters the data, it is rounding up the value as shown in the picture.
However, to not round the values, I did this
a4_range.setNumberFormat("$#, ##0.000000");
This works but has extra trailing zeroes which I do not want as below,
What I want is when user comes and enters 56.768 in that range, the value should be exactly $56.768 and NOT 56.768000 and NOT have it round off to any decimal places.
Similarly, if the user enters 34.3 then it should be $34.3 and if user enters 8.98945 it should be $8.98945
How do I achieve this?
Try this:
a4_range.setNumberFormat("$0.#######");
I have created an HTML web app in google script this works like a calculator, This app works fine if I add the input in descending order however if I skip the order and update in put data numbers randomly in any column then I am not getting the output properly
Example:- update the numbers in box number 4 and 5 then update in box number 1 you will find the differences in total numbers
Please refer the attached sheet for detailed script
Project Name- Project Proposal Form
$("#rTpe1").keyup(function(e){
$("#rFor1").val(this.value * $("#PerHourRate1").val());
$("#rFor3").val( Number($("#rFor1").val()) +Number($("#rFor2").val()))
});
$("#rTpe2").keyup(function(e){
$("#rFor2").val(this.value * $("#PerHourRate2").val());
$("#rFor3").val( Number($("#rFor1").val()) + Number($("#rFor2").val()))
});
$("#rTpe12").keyup(function(e){
$("#rFor12").val(this.value * $("#PerHourRate3").val());
$("#rFor3").val( Number($("#rFor1").val()) + Number($("#rFor2").val())+ Number($("#rFor12").val()))
});
$("#rTpe13").keyup(function(e){
$("#rFor13").val(this.value * $("#PerHourRate4").val());
$("#rFor3").val( Number($("#rFor1").val()) + Number($("#rFor2").val())+ Number($("#rFor12").val())+ Number($("#rFor13").val()))
});
I could be wrong, but I think that's the main culprit:
If your work your way top to bottom, the output in '#rFor3' is not affected. For example, if you enter values in the first field ('#rTpe1'), this statement
Number($("#rFor2").val()))
will evaluate to '0' because '#rFor2' probably contains an empty string at this point and Number("") will get you a zero. Because all subsequent input fields reference the results of previous calculations ('rTpe2' references 'rFor1', 'rTpe12' references both 'rFor1' and 'rFor2', etc), the sum will come out as correct.
Now consider the reverse scenario. For simplicity, let's make all your rates equal to 1. If you enter the value of '5' into 'rTpe12', the value of 'rFor3' will be
Number("") + Number("") + Number(5*1) == 5; //the first two inputs will contain empty strings at this point
The output of '#rFor3' would be 5. If you go up a step and enter the value of '2' into 'rTpe2', the value of the 'rFor3' output will change to
Number("") + Number(2*1) == 2; the first input will contain an empty string.
The code is not easy to understand, so even if this solution doesn't work for you, consider caching your DOM elements to improve performance and make your code more readable. Currently, you are using jQuery selectors to search the DOM over and over again, which is a serious performance drag. You could also store your calculated value as a variable and simply add values to it instead of recalculating on each input. For example
$('document').ready(function(){
var total = 0;
var input1 = $('#input1');
var input2 = $('#input1');
var input3 = $('#input1');
var output = $('#output');
input1.keyup(function(e){
var value = Number(this.value);
sum += value;
output.val(sum);
});
});
I'm using the following code added to my DBGrid - OnCellClick event
procedure TForm2.DBGrid1CellClick(Column: TColumn);
begin
if dbmodule.comenziDataSet.Active then
begin
if not Assigned(dbgridCelulaForm) then
begin
dbgridCelulaForm := TdbgridCelulaForm.Create(Self);
dbgridCelulaForm.DBMemoCelula.DataSource := dbmodule.comenziSource;
end;
dbgridCelulaForm.Visible := False;
dbgridCelulaForm.Visible := True;
dbgridCelulaForm.DBMemoCelula.DataField := Column.FieldName;
dbgridCelulaForm.Caption := Format('%s / randul: %d',[Column.FieldName, DBGrid1.DataSource.DataSet.RecNo]);
end;
end;
dbgridCelulaForm = name of the form containing the TDBMemo
DBMemoCelula = name of the TDBMemo
dbmodule.comenziDataSet = comenziDataSet is the name of the DataSet and dbmodule is the name of a data module (unit, like forms) - the DataSet is on the data module, so, dbmodule.comenziDataSet
dbmodule.comenziSource = same as data set, a DataSource on a data module, the source is named comenziSource
Ok so what this code does:
Once I click a cell on my DBGrid it pops up a form (named dbgridCelulaForm) which contains a TBMemo (named DBMemoCelula) and it shows me the information contained in that cell (like, a Customer Name for example, or whatever the cell is holding, in my db)
This is fine, my problem is I can't select rows now in DBGrid, well, I can but once I do the 1st place I click (a cell, any) on the particular row I want to select with my mouse, then cell activates and the form pops up.
Is it possible to use this code in DBGrid - OnDblClick event instead of the OnCellClick ?
Meaning once i double click a row / cell the form should pop up and show me the info, but double click - not single click.
That way, I can still select the row and still view the info in the cell if I need to.
Or any other way/place to use/receive this functionality.
Any thoughts?
I can post a quick video of everything if my explanation is ambiguous and you think that would help, just tell me in the comment / answer.
Also, I'm using RAD Studio 10 Seattle and dbexpress components for the database - if that helps.
Thanks!
The following code shows how to access the Column and Row coordinates of a dbl-clicked cell of a TDBGrid, and the string value of the cell contents.
As written, it displays the cell's Column and Row number + string contents on the form's caption. Up to you what you actually do with these values.
It work because the dataset cursor on the dataset connected to the DBGrid is moved to the dataset row corresponding to the cell where the mouse pointer is.
type
TMyDBGrid = class(TDBGrid);
procedure TForm1.DBGrid1DblClick(Sender: TObject);
var
ARow,
ACol : Integer;
Pt : TPoint;
CellValue : String;
begin
// First, get the mouse pointer coordinates
Pt.X := Mouse.CursorPos.X;
Pt.Y := Mouse.CursorPos.Y;
// Translate them into the coordinate system of the DBGrid
Pt := DBGrid1.ScreenToClient(Pt);
// Use TDBGrids inbuilt functionality to identify the Column and
// row number.
ACol := DBGrid1.MouseCoord(Pt.X, Pt.Y).X -1;
ARow := DBGrid1.MouseCoord(Pt.X, Pt.Y).Y;
CellValue := DBGrid1.Columns[ACol].Field.AsString;
Caption := Format('Col:%d Row:%d Cell Value:%s', [ACol, ARow, CellValue]);
end;
Note that I've used the Caption property of the form to display the grid cell info just as a quick n dirty way of showing the information somewhere. Of course you could equally well display it on another area of the form or somewhere on a different form entirely. The above code will work equally well in the grid's OnCellClick event, btw.
As noted in a comment, you can use the grid's SelectedField property instead of the above, but personally I think the above is more instructive of how to work with a DBGrid, because it shows how to get the cell's Column and Row coordinates. See the DBGrid's SelectedField, SelectedIndex and SelectedRows properties in the Online Help for more info on useful properties of the TDBGrid.
Update You asked in a comment for an example of showing the information on another form. Let's suppose this form is called OtherForm, is in a unit OtherFormu.Pas and is created before the DBGrid1DblClick evenbt is called. You need to use this unit in the Useslist of the unit which contains the DBGrid. Let's suppose this other form contains a TMemo control called Memo1. Then, you could write your DBGrid1DblClick hanndler like this:
procedure TForm1.DBGrid1DblClick(Sender: TObject);
[as above]
begin
[ as above ]
CellValue := DBGrid1.Columns[ACol].Field.AsString;
OtherForm.Memo1.Lines.Add(Format('Col:%d Row:%d Cell Value:%s', [ACol, ARow, CellValue]));
end;
I'm pretty new to MVC and I'm having a hard understanding how to get the values (basically the IDs) to checkboxes that I'm generating. Here are my checkboxes:
<div id='myCheckboxDiv'>
<input type="checkbox" onclick="checkAll(this)">Check All
#foreach (var form in #Model.DetailObject.DoaFormGroupDocuments)
{
<br>
var checkBoxId = "chk" + form.DocumentId;
#Html.CheckBox(checkBoxId, new { value = form.DocumentId, #checked = true });
#form.DocumentName;
}
</div>
Essentially what I want to do is get the ID to which ever checkbox is checked and save it in to a list after I click a save button at the bottom of the page.
I have run across something like this to handle everything but I'm not quite sure how to use it really...
var values = $('#myCheckboxDiv').find('input:checkbox:checked').map(function () {
// get the name ..
var nameOfSelectedItem = this.attr('name');
// skip the ‘chk’ part and give me the rest
return nameOfSelectedItem.substr(3);
}).get();
The only thing you need to think about is the value of the name attribute your checkbox(es) will have. The way you're handling it right now, your post body is going to have a fairly randomized collection of chkN-named parameters, where N is some number. The modelbinder will need something similarly named as a parameter to your action method in order to bind the posted values to something useful. That's a tall order for something that will be some what variable (the DocumentId values).
The best option would be to set up your checkboxes, instead, as a collection, which means giving them names chk[0], chk[1], etc. Then in your action you can accept a parameter like List<string> chk, and that will contain a list of all the values that were posted.
I'm attempting to alter the contents of certain parts of a HTML form through usage of the URL. For a text field, I'm aware that this will suffice,
http://<domain>?fieldname=ping&anotherfield=pong
On the form there are multiple select braces (drop down boxes); Is it possible to pick an int or string value through the url for this?
There seems to be little documentation on this (or even people trying to do the same)...
You haven't specified how you want to do this, but I'll assume that you want to use JavaScript:
To get a value from QueryString:
getQueryStringArgument = function(key) {
var hu = window.location.search.substring(1);
var gy = hu.split("&");
for (i = 0; i < gy.length; i++) {
var ft = gy[i].split("=");
if (ft[0] == key)
return ft[1];
}
}
To set the selected value of the select list:
document.getElementById("sel").value = getQueryStringArgument("id");
For a text field, I'm aware that this will suffice
No, it won't (at least, not in a generic way).
For a text field, the default value is specified by the value attribute. There might be a server side script that populates it based on query string data, but there doesn't have to be.
On the form there are multiple select braces (drop down boxes); Is it possible to pick an int or string value through the url for this?
Again, this requires an attribute to be set (selected on <option>), and that could (again) be set by a server side script based on the query string data.