Forum OpenACS Development: validate a dynamic element form.

Collapse
Posted by sergio cubero on
Hi.

I like to correct an error in module assesment, an "packages/assessment/www/asm-admin/item-edit-mc-choices.tcl".

I like to validate the element form "percent.$choice" so that only supports integer values.

Currently there's no exist validation on form fields.

I want to add to the construction of this code form for validate element:

} -validate {
{value
{[string length $value] >= 3}
"\"value\" must be a string containing three or more characters"
}

Where value = percent.$choice_id

but, seems to be this type of dynamic array elements do not work with this model.

I've also tried using a javascript but given the type of constructing a form where the elements are built dynamically, nor can I implement this solution.

Anyone can tell me like it could validate this form element?

Thanks.

This's de code on create the element form:

append ad_form_code "\{percent.$choice_id:text,nospell \{label \"[_ assessment.Percent_Score]\"\} \{value \"$default_percent\"\} \{html \{size 5 maxlength 5\}\} \{help_text \"[_ assessment.Percent_Score_help]\"\}\}\n"
ns_log notice "choice_id $choice_id"

}

Collapse
Posted by Dave Bauer on
You can set the datatype to integer instead of text.

This should simplify this particular case since there is already a built in validation for integer.

You'd have to build the validate block dynamically also as a list and then add it to the ad_form otherwise.

Collapse
Posted by sergio cubero on
Hi Dave.

I changed the type of form element to integer and it works.

It is a good solution.

Thank you very much.

append ad_form_code "\{percent.$choice_id:integer,nospell \{label \"[_ assessment.Percent_Score]\"\} \{value \"$default_percent\"\} \{html \{size 5 maxlength 5\}\} \{help_text \"[_ assessment.Percent_Score_help]\"\}\}\n"
ns_log notice "choice_id $choice_id"

}

Collapse
Posted by Ryan Gallimore on
Hi Sergio,

Here is a great document for ad_form.

https://openacs.org/storage/view/ad-form-quick-ref.pdf

It includes a listing of datatypes that can automatically validate form input, for example, email.

Ryan