PDA

View Full Version : [CLOSED] Need sample of VType between two fields where one or the other must be set



michaeld
Jun 05, 2013, 7:12 AM
The tricky part is both fields need to be marked as invalid with vtypeText if one or the other is not set.

Any thoughts?

Daniil
Jun 05, 2013, 12:05 PM
Hi @michaeld,

Here is a sample for Ext.NET v1.
http://forums.ext.net/showthread.php?12296#post50288

It might require some changes to get it working with v2.

michaeld
Jun 09, 2013, 9:16 AM
I found another way to do it.

Daniil
Jun 10, 2013, 6:26 AM
If you find time, please share. Someone can much appreciate it, if find this thread in the future.

michaeld
Jun 10, 2013, 11:26 PM
Ext.apply(Ext.form.VTypes, {
SorZ: function (value, field) {
if (value && value.length) {
#{Z}.allowBlank=true;
#{S}.allowBlank=false;
#{Z}.clearInvalid();
return true;
}
return (#{Z}.getValue() !=null );
},
SorZText: 'Must specify S or Z',
ZorS: function (value, field) {
if (value && value.length) {
#{Z}.allowBlank=false;
#{S}.allowBlank=true;
#{S}.clearInvalid();
return true;
}
return (#{S}.getValue() !=null );
},
ZorSText: 'Must specify S or Z'
});

Controls S & Z are initialized with allowblank=false and Z's VType is set to ZorS, and S's VType is set to SorZ.

It wasn't perfect because it doesn't cause revalidation after the changed settings, but it had the accidental purpose of working well enough to do the job.

It feels like a hack, and it is, but till someone wants to code a more appropriate way to do this, it'll have to do.

Daniil
Jun 11, 2013, 5:48 AM
Thank you for sharing!

What about this solution? Seems to work well.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script>
Ext.apply(Ext.form.VTypes, {
multipleAllowBlankFalse: function (value, field) {
var ct = field.up("fieldcontainer"),
valid = true;

ct.items.each(function (item) {
if (Ext.isEmpty(item.getValue())) {
valid = false;
}

if (item !== field && !item.validating) {
item.validating = true;
item.validate();
item.validating = false;
}
});

return valid;
},

multipleAllowBlankFalseText: "This or other related field is empty!"
});
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:FieldContainer runat="server">
<Items>
<ext:TextField runat="server" Vtype="multipleAllowBlankFalse" ValidateBlank="true" />
<ext:TextField runat="server" Vtype="multipleAllowBlankFalse" ValidateBlank="true" />
<ext:TextField runat="server" Vtype="multipleAllowBlankFalse" ValidateBlank="true" />
</Items>
</ext:FieldContainer>
</form>
</body>
</html>