parsley.js equalto Not invalidating if equal to field changes - c#

I'm working in c# using web forms,
when integrating parsley for input validation it doesn't make the input with the 'equalto' arttirbute invalid if the equal to field changes.
<input type="password" runat="server" id="passwordTB" name="passwordTB" class="form-control" data-parsley-required="true" data-parsley-trigger="change" autocomplete="off" data-parsley-length="[7,40]" />
Repeat Password:
<input type="password" runat="server" id="passwordTBRepeat" name="passwordTBRepeat" class="form-control" data-parsley-required="true" data-parsley-trigger="change" data-parsley-equalto="#passwordTB" autocomplete="off" data-parsley-length="[7,40]" />
I would expect the passwordTBRepeat to validate itself and become invalid if passwordTB changed but it doesn't.
I'm using parsley v2.1.2 and jquery 2.1.4.
Is this by design or am I doing something wrong?

Currently, Parsley doesn't deal very well with interdependencies.
For now, you could manually call validate when the source input updates.

Related

how to get data-* attribute with asp.net ()

I have:
<input name="input4" type="text" id="input4" disabled="disabled" class="jsx-3771882255" data-id="0">
I want get data of data-id by C#;
string s=input4.Attributes["data-id"].ToString(); //(can'tuse this!)
You have the disabled attribute set on your text box, this will not get submitted to the server, use the readonly attribute instead of the disabled attribute.
#vuong quang - Can you check my code and implement it's working for me and also I shared my code with a screenshot.
HTML Code
Add runat="server"
<input type="text" name="name" value="0" data-id="101" runat="server" id="txtvalue" />
HTML Code
Code behind
string id = txtvalue.Attributes["data-id"].ToString();
Check below screenshots
CS Page Code

List property ignored by controller if 0 index is missing

I'm building a webform in c# .net mvc using mongodb to store information. The form works with a company object that has a property that is a List of Addresses, called addressdata. When the form is submitted, the company object is sent to the controller and then upserted into MongoDB. The input names take the form
<input type="text" name="Company.addressdata[a].city" />
Where "a" is the index in the list. This all works great! The list of address objects is created upon submission and inserts into mongoDB.
However, I just added the ability to delete addresses, and now I'm running into trouble. I have noticed that when a user deletes the first row, all the rows after are lost. So, if they delete the 0 index, the Company object will not populate the list of Addresses and thus they will not go into MongoDB.
Is there a way to work around this? Is this how it's designed to work? It seems like too much to renumber all of the following rows with the new index, but is that what it takes? Or is there another way?
In my experience, that's by design. The indexes must start from 0, or you have to define your own indexes for each of them with a special element.
This article shows an example of that: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/
<form method="post" action="/Home/Create">
<input type="hidden" name="products.Index" value="cold" />
<input type="text" name="products[cold].Name" value="Beer" />
<input type="text" name="products[cold].Price" value="7.32" />
<input type="hidden" name="products.Index" value="123" />
<input type="text" name="products[123].Name" value="Chips" />
<input type="text" name="products[123].Price" value="2.23" />
<input type="hidden" name="products.Index" value="caliente" />
<input type="text" name="products[caliente].Name" value="Salsa" />
<input type="text" name="products[caliente].Price" value="1.23" />
<input type="submit" />
</form>
So you have options, either:
Update indices when deleting, or
Define arbitrary indices

Why I can't show and edit double\floated values into this JQuery view?

I am very new in C#/.NET and JQuery view development and I am finding some difficulties trying to create input form to show and modify double values.
I have the following situation, into my view I have this input form:
<div class="ui-field-contain">
<label for="Severity">Severity:</label>
<input type="number" id="Severity" name="Severity" min="0" max="10" step=".1" value="#Model.Severity))" />
</div>
The value of the Severity field of my model object (#Model.Severity) is: 3.0 (I checked it using the debugger) but this value is not shown into my previous input tag.
The severity field is declared as double value into my model object, in this way:
public double? Severity { get; set; }
Why it can't correctly work?
I am thinking that maybe is a formattation\internazionalization problem because I see that other views use the , character for the floatted number (3,0 instead 3.0)
What canI do to fix this issue?
Tnx
Well thats because there is a extra closing angular braces ')' in the value which is being set to the severity fld
Replace
<input type="number" id="Severity" name="Severity" min="0" max="10" step=".1" value="#Model.Severity))" />
with
<input type="number" id="Severity" name="Severity" min="0" max="10" step=".1" value="#Model.Severity)" />
Happy Coding :)

Jquery validation for a name along with class [duplicate]

I have an HTML form that I'm processing with Perl CGI, like so:
<form action="process.cgi" id="main">
<input type="text" name="foo" class="required" />
<input type="text" name="foo" class="required" />
<input type="text" name="foo" class="required" />
</form>
And I'm validating it with the jQuery Validation plugin. Trouble is, when I call $('#main').valid(), it only checks that the first field is non-empty. How to I get it to check all the fields?
OFFICIAL DOCUMENTATION:
jqueryvalidation.org/reference/#link-markup-recommendations
"Mandated: A 'name' attribute is required for all input elements needing validation, and the plugin will not work without this. A 'name' attribute must also be unique to the form, as this is how the plugin keeps track of all input elements. However, each group of radio or checkbox elements will share the same 'name' since the value of this grouping represents a single piece of the form data."
<input type="text" name="foo" class="required" />
<input type="text" name="foo" class="required" />
<input type="text" name="foo" class="required" />
Quote OP:
Trouble is, when I call $('#main').valid(), it only checks that the
first field is non-empty. How to I get it to check all the fields?
It has nothing specifically to do with .valid() and it will fail the same using other jQuery Validate methods. That's because all three fields have the same name of foo. For this plugin each input must have a unique name.
DEMO: jsfiddle.net/xaFZj/
EDIT:
You cannot have duplicate names while using this plugin. This demo clearly shows that the plugin will fail when the name attribute is duplicated. There is no workaround since the name attribute is how the plugin keeps track of the form elements.
jsfiddle.net/ed3vxgmy/
The only exception is a radio or checkbox group where the elements in each grouping will share the same name.

unable to add value to html textbox of type password

hi all am trying to load values from cookies to the text box.My HTMLis as below
<fieldset class="boxBody">
<label id="dis" style="margin:0 auto;display:none"></label>
<label>Username</label>
<input type="text" name="Username" id="txtUsername" runat="server" tabindex="1" placeholder="Username" />
<label>Password</label>
<input type="password" name="password" id="txtpassword" runat="server" placeholder="Password" tabindex="2" />
</fieldset>
and my code in pageload is
txtUsername.Value = Request.Cookies["SN"]["UserName"];
txtpassword.Value = Request.Cookies["SN"]["Password"];
what happens is instead of password only the placeholder is visible.when i change the type to text it works.Any way to add text when the page is loaded
Set the attribute, as a workaround:
txtPassword.Attributes.Add("value", Request.Cookies["SN"]["Password"])
Disclaimer: Pre-filling passwords may not be a good idea.
Do you really need to hide the password cause if its not you can change the text of txtPassword to asterisks
textmode="Password"

Categories

Resources