Foolproof JavaScript Errors

Sep 3, 2010 at 11:28 AM

Hi There,

I downloaded foolproof dll and referenced it in my project but it doesn't work for me saying javascript error mentioned below.

$.validator.methods[method] is undefined
http://localhost:3848/Scripts/jquery.validate.min.js

I tried to include MvcFoolproofJQueryValidation.min.js and MvcFoolproofValidation.min.js but no luck.

Please help.

Thanks.

Coordinator
Sep 3, 2010 at 1:47 PM

This likely means that jquery.validate.min.js isn't being included. Use FireFox's FireBug, and ensure it's being successfully included using the "Net" tab.

Sep 3, 2010 at 4:27 PM

Hi Nickriggs,

Thanks a lot for your reply. It works.

Scenario at my end is mentioned below; 

CheckBox1

Decimal(Amount)1

CheckBox2

Decimal(Amount)2

Now on both the amount field i kept RequiredIfTrue attribute; But it doesn't behave as expected because decimal has default value 0.00, Even If i checked checkbox2 and left decimal(amount)2 as 0.00, it understands that value has been provided.

I hope you get what I want to explain. Can you please suggest a work around for the same.

Thanks.

Jigar.

 

Coordinator
Sep 3, 2010 at 4:31 PM

Send me your view model code, either here or via direct message. 

Sep 3, 2010 at 5:11 PM

Hi Nickriggs,

thanks a lot for your prompt response

Please find the below mentioned view model.

Public Class TestModel

<ScaffoldColumn(False)>
Public Property id As Integer

<DisplayName("Name")>
<UIHint("Autocomplete")>
Public Property name As String

<UIHint("Checkbox")>
Public Property isAmountOne As Boolean

<RequiredIfTrue("isAmountOne")>
Public Property amountOne As Decimal

<UIHint("Checkbox")>
Public Property isAmountTwo As Boolean

<RequiredIfTrue("isAmountTwo")>
Public Property amountTwo As Decimal

End Class

Thanks a lot,

Jigar
Coordinator
Sep 3, 2010 at 6:32 PM

Make the Decimal properties Nullable, Like this:

Public Class TestModel

    <ScaffoldColumn(False)>
    Public Property id As Integer

    <DisplayName("Name")>
    <UIHint("Autocomplete")>
    Public Property name As String

    <UIHint("Checkbox")>
    Public Property isAmountOne As Boolean

    <RequiredIfTrue("isAmountOne")>
    Public Property amountOne As Nullable(Of Decimal)

    <UIHint("Checkbox")>
    Public Property isAmountTwo As Boolean

    <RequiredIfTrue("isAmountTwo")>
    Public Property amountTwo As Nullable(Of Decimal)

End Class

 

Sep 3, 2010 at 7:11 PM

Hi Nickriggs,

Thanks a lot for your valuable inputs. This works if i use normal text-box, but in my case I am using telerik currency text box; by default they display "Enter Value" text.

So, In this case I left with only 2 options; either I identify property type in foolproof and consider 0 / 0.00 as empty field ( ofcourse in case of integer, decimal, double) OR I change the behavior of telerik currency text box.

Please suggest Is it possible to do so with Foolproof? If Yes, please suggest where to begin. I tried to compile the Foolproof code but solution doesn't load the solution saying it didn't find some project in MSBuild folder.

By the way, I included MvcFoolproofJQueryValidation.min.js and MvcFoolproofValidation.min.js in site master; when my login page gets loaded MvcFoolproofValidation js gives error like "Sys is not defined"

Thanks a lot again,

Jigar.

Coordinator
Sep 3, 2010 at 7:38 PM

So the best way around this situation might be to build your own contingent validator:

Public Class CustomDecimalRequiredAttribute

    Inherits ContingentValidationAttribute

    Shared Sub New()
        Register.Attribute(GetType(CustomDecimalRequiredAttribute))
    End Sub

    Public Sub New(ByVal dependentPropery As String)
        MyBase.New(dependentPropery)
    End Sub

    Public Overloads Overrides Function IsValid(ByVal value As Object, ByVal dependentValue As Object, ByVal container As Object) As Boolean

        If (Boolean.Parse(dependentValue.ToString())) Then
            Return (value IsNot Nothing AndAlso CType(value, Decimal) <> 0)
        End If

        Return True

    End Function

End Class

Public Class TestModel

    Public Property id As Integer

    Public Property name As String

    Public Property isAmountOne As Boolean

    <CustomDecimalRequired("isAmountOne")>
    Public Property amountOne As Nullable(Of Decimal)

    Public Property isAmountTwo As Boolean

    <CustomDecimalRequired("isAmountOne")>
    Public Property amountTwo As Nullable(Of Decimal)

End Class

Sep 4, 2010 at 8:19 AM

Hi Nickriggs,

many thanks for the your inputs. I did the exactly what you suggested. But while submitting the form it again gives the same error like I mentioned in my first post.

i.e. $.validator.methods[method] is undefined
http://localhost:3848/Scripts/jquery.validate.min.js

Though RequiredIfTrue attribute works fine.

Do I need to include some script related to this new CustomDecimalRequiredAttribute in js?

Thanks,

Jigar.

Coordinator
Sep 9, 2010 at 2:22 PM

Sorry for the late response. 

This is because it's looking for a JavaScript version of your custom validator. I cover how to build client side validators with Foolproof here: http://www.nickriggs.com/posts/client-side-model-aware-validation/

Sep 10, 2010 at 11:17 PM

 

Hi Nickriggs,

thanks a lot for your response. My firebug keeps saying that "Sys is not defined" for MvcFoolproofValidation.min.js; Am I missing something? Or do I have to follow some steps to solve this?

Again, thanks a lot Nick; I really appreciate the way you are helping me to learn. 

Thanks,

Jigar

 

Coordinator
Sep 27, 2010 at 9:22 PM

Sorry for the very late response. My guess is that you are missing one of the following script references:

<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>