MVC razor behaving unexpectedly, displaying incorrect textbox values - asp.net-mvc-4

I have a little snippet of code here:
View:
#foreach (var lines in Model.KVpairs)
{
#Html.TextBoxFor( m => lines, new { placeholder = lines })
}
In my application, I load the view containing this code twice, the first time, it works as intended, the second time, the values for all of the textboxes are the same value, but the placeholders are all different. Or in other words, the placeholders are working as intended, but the value(the actual text inside the box) is not.
Am I missing something very obvious?
EDIT:
wanted to add some pics:
before I sumbit the form, ive entered these values
Here you can see the values of the KVpairs
And this is the result I get after form submission
And these are the placeholders after the submission

Instead of foreach loop try using for loop like this:
#for (var i = 0; i < Model.KVpairs.Count(); i++)
{
#Html.TextBoxFor( m => Model.KVpairs[i], new { placeholder = lines })
}

Related

Get the caret position for Blazor text input

I am working on a Blazor textarea input. What I want to achieve is whenever user types "#" character, I am going to popup a small window and they can select something from it. Whatever they select, I will insert that text into the textarea, right after where they typed the "#".
I got this HTML:
<textarea rows="10" class="form-control" id="CSTemplate" #bind="original" #oninput="(e => InputHandler(e.Value))" #onkeypress="#(e => KeyWasPressed(e))"></textarea>
And the codes are:
protected void InputHandler(object value)
{
original = value.ToString();
}
private void KeyWasPressed(KeyboardEventArgs args)
{
if (args.Key == "#")
{
showVariables = true;
}
}
protected void AddVariable(string v)
{
original += v + " ";
showVariables = false;
}
This worked very well. The showVariables boolean is how I control the pop-up window and AddVariable function is how I add the selected text back to the textarea.
However, there is one small problem. If I've already typed certain text and then I go back to any previous position and typed "#", menu will still pop-up no problem, but when user selects the text and the insert is of course only appended to the end of the text. I am having trouble trying to get the exact caret position of when the "#" was so I only append the text right after the "#", not to the end of the input.
Thanks a lot!
I did fast demo app, check it https://github.com/Lupusa87/BlazorDisplayMenuAtCaret
I got it - I was able to use JSInterop to obtain the cursor position $('#CSTemplate').prop("selectionStart") and save the value in a variable. Then use this value later in the AddVariable function.
you can set your condition in InputHandler and when you are checking for the # to see if it's inputed you can also get the length to see that if it's just an # or it has some characters before or after it obviously when the length is 1 and value is # it means there is just an # and if length is more than one then ...

I would like to grey out the submit button until required fields in a pdf form have been filled out

I am recently task with collecting data using a pdf form, some fields in the form are required but not all fields, I have created a submit button and the department will received the form fill out, now the form needs to be reset when submitted. so i add a button to submit the form and then reset it. the problem is that if someone fills the form and hits submit missing a required field then when they hit ok all the fields are being reset and the person needs to start over. Please Advice.
My idea is to gray out the submit button until all the required fields are fill out, no idea how to do this on adobe pro.
Thanks
As you immediately reset the form after submitting (what happens when the submit fails?), greying out or making read-only is a way to go.
Assuming that you did set the required property for the required fields, you could add the following snipped to your Calculation script:
var cnt = 0 ;
for (var i = 0 ; i < this.numFields ; i++) {
var mf = this.getNthFieldName(i) ;
if (mf.type != "button" && mf.type != "signature") {
if (mf.required == true && mf.value == mf.defaultValue) {
cnt++ ;
}
}
}
if (cnt > 0) {
this.getField("mySubmitButton").readonly = true ;
} else {
this.getField("mySubmitButton").readonly = false ;
}
And that should do it.
However, this approach is not very efficient, and for bigger number of fields and just a few required ones, it might be better to create an array of the required field names, and loop through this array instead of all fields.

Get input type in Geb

I am using Geb to write a script that will test a survey many times with random input to make sure nothing breaks. I would like to iterate through every input on a form and do different things depending on the input type.
For example:
while ($("form").find("input", j)) {
if($("form").find("input", j) == "checkbox"){
//check it sometimes
}
else if($("form").find("input", j) == "select"){
//select a random option
}
j++
}
I'm not exactly sure how the survey is going to work yet, so I would rather go down the page as a human would instead of doing all checkboxes first and then all selects etc. It is possible to check the type of input like my example?
Additionally, I notice I am repeating the $("form").find("input", j). Can I make that into a variable like in jQuery?
Simply collect all your inputs and selects in a navigator and iterate over all of them. Use is(String tagName) to detect select elements and #type attribute accessor to detect other element types:
def form = $("form")
def formElements = form.find("input") + form.find("select")
formElements.each { Navigator element ->
if (element.is("select") {
//select a random option
}
if (element.#type == "checkbox") {
//check it sometimes
}
}

Livecycle: Referencing objects in repeated subforms

I have a form that I want to lock for presentation once it is filled out. I know how to make this happen with a button to render the text fields read-only. Now I have a form that involves repeated subforms (added as needed). How can I script a single button so it will work for the objects in all the subforms?
The subforms are iterations of "ItemGroup". I need to make "ItemGroup.Item" and "ItemGroup.ItemRx" read-only, and "ItemGroup.ItemHeader.Button" invisible.
I'm at home, hence untested. Let me know if you bump into trouble.
var sfSom = "<path/somExpression to subform containing ItemGroups>"; var nn, n = xfa.resolveNode(sfSom).nodes;
for (var i = 0; i < n.length; i++) {
nn = n.item(i);
if (nn.name == "ItemGroup" && nn.className == "subform") {
/* change stuff here. Decide if Item and ItemRx should be read-only, calculate or protected. For now, we'll settle for hiding the button: */
nn.ItemHeader.Button.presence = "hidden";
}
}

Dojo EnhancedGrid and programmatic selection

Here's my problem: in my application I have a Dojo EnhancedGrid, backed up by an ItemFileReadStore. The page flow looks like this:
The user selects a value from a selection list.
The item from the list is posted on a server and then the grid is updated with data from the server (don't ask why, this is how it's supposed to work)
The new item is highlighted in the grid.
Now, the first two steps work like a charm; however, the third step gave me some headaches. After the data is successfully POSTed to the server (via dojo.xhrPost() ) the following code runs:
myGrid.store.close();
myGrid._refresh();
myGrid.store.fetch({
onComplete : function(items) {
for ( var i = 0; i < items.length; i++) {
if (items[i].documentType[0].id == documentTypeId) {
var newItemIndex = myGrid.getItemIndex(items[i]);
exportMappingGrid.selection.deselectAll();
exportMappingGrid.selection.addToSelection(newItemIndex);
}
}
}
});
Now, the selection of the grid is updated (i.e. the selection object has a selectedIndex > 0), but visually there's no response, unless I hover the mouse over the "selected" row. If I remove the .deselectAll() line (which I suspected as the culprit) then I sometimes end up with two items selected at once, although the grid selectionMode attribute is set to single.
Any thoughts on this one?
Thanks a lot.
You need to use setSelected(), like so
exportMappingGrid.selection.setSelected(newItemIndex, true);
The second parameter is true to select the row, false to unselect it.
This is what works for me:
grid.selection.clear();
grid.selection.addToSelection(newItemIndex);
grid.selection.getFirstSelected();
Jon