Re: [Cppcms-users] Setting field value after form.load() still fails validation
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-06-15 07:29:46
|
If this a default value than - you should set it before you render the form so it would be seen in the HTML - you should allow the widget to be empty and check if it is widget_name.set(). If it is not set use default, Using c.form.load(context()) c.form.num.value(10); c.form.validate() Is not correct. You should either do if(request()=="POST") { c.form.load(context()) c.form.validate() } else { c.form.num.value(10); render("myform",c); } Or Do not sent constrains on a num and then c.form.load(context()) c.form.validate() if(c.form.num.set()) { realval = 10;// we got default } else { realval = num.value(); // do other checks } Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ ----- Original Message ----- > From: "ele...@ex..." <ele...@ex...> > To: ele...@ex... > Cc: cpp...@li... > Sent: Thursday, June 14, 2012 4:59 PM > Subject: Re: [Cppcms-users] Setting field value after form.load() still fails validation > >> I've looked through the form.h header into widgets::numeric::load >> >> and found this: >> >> ss.imbue(context.locale()); >> ss>>value_; >> if(ss.fail() || !ss.eof()) >> valid(false); >> else >> set(true); >> > > > Sorry for the repeat emails, I pressed space key several times without > realizing that the focus was set on the "send" button and ive been > working > for 14 hours today. > > Question is, is it proper to set a validation flag without to running > form::validate()? > > What I have is a numeric<int> widget which can either take an int or a > date. Ive overloaded form::load to calculate days from a given date. > > Petr > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |