I want to use server side filtering depending on characters entered in the dropdownlist.
I am using following code:
#(Html.Kendo().DropDownListFor(m => m.VoucherReceiverCustomerId)
.Name("VoucherReceiverCustomerId")
.DataValueField("Value")
.DataTextField("Text")
.Filter(FilterType.StartsWith)
.AutoBind(false)
.MinLength(1)
.Delay(250)
.DataSource(ds => ds
.Read(read => read.Url(Url.Action("Customer_List", "Customer")))
.ServerFiltering(true)
)
.Events(evt => evt.Filtering("test").Open("test2"))
)
I'd expect the list to send the dataSource request after the user entered at least one character.
But in fact the list immediately sends the request after clicking on the dropdownlist (in order to enter characters). Moreover neither event Filtering nor Opening fire.
Increasing parameter for option MinLength to > 1 results in the actual expected behaviour.
To work around this issue I could use the Filtering event and manually request the dataSource after a character has been entered.
But how would I prevent the dataSource from reading until then?
Normally setting option AutoBind is enough but in this case not.
Funny - setting option MinLength to 0 actually behaves as one would expect for value 1.
So I kind of got a solution now. However, the documented problem still exists.
Related
I want to make things like put masks and validate using regular expression, or using other way, verify if field is empty, and many other things, in a play form.
For example:
#inputText(
myForm("anydata"),
'id -> "anyData",
'_label -> "Any Data"
)
I want to put a mask of only characters/numbers/etc, and put a mask to format this field. Have some helper of play framework to do this, or some other way?
Thanks in advance.
Validation is pretty simple in Play! You will have to implement this on the Form object.
From the documentation:
val userFormConstraints2 = Form(
mapping(
"name" -> nonEmptyText,
"age" -> number(min = 0, max = 100)
)(UserData.apply)(UserData.unapply)
)
The age field has a validation for min and max number values. You could roll your own custom validation. I've had to do something like to this:
"pairs" -> seq(text).verifying(pairs => pairs.forall(pair => pair.contains(':')))
When you are mentioning putting masks I assume that you want to use some JavaScript - client side - pre-validation. There's nothing to do with Play in this subject, you can/need just to find proper plugin which does the thing within the browser, i.e. jQuery Masked Input.
You will need to validate this on the server side as well (for better security) anyway in such case you need to create own validator which respects the same rules as the client side one.
I have some checkboxes and their name maps to a column in my activerecord model. Problem is, when the checboxes are selected, they appear in the params array in Sinatra, which works fine. But when they are deselected, the params never contains :checkbox => false. It only contains :checkbox => true. So the user can go from deselected to selected, but never vice versa as the params hash for :checkbox => false is never passed.
I feel like I am missing something fundamental here. Please help.
Thanks
A control in a HTML form only gets submitted to the server if it is “successful’. For checkboxes this means that it is checked. An unchecked checkbox doesn’t get submitted. This means that in Sinatra the value of params[:the_checkbox] is either the value of the checkbox specified in the HTML (if you don’t specify a value this will be the default which is the string 'on') if it is checked, or will be nil since nothing will have been submitted.
The obvious solution is to explicitly check for nil, and then assume that the checkbox is unchecked in that case:
checkbox_value = params[:the_checkbox].nil? ? false : true
Another option is to make use of the fact that the name/value pairs of the form data are sent to the server in the order that they appear in the document, and that when Sinatra sees a repeated name when parsing the data it will override the earlier value with the later one. This means that you can do something like this in the HTML:
<input type='hidden' name='the_checkbox' value='false' />
<input type='checkbox' name='the_checkbox' value='true' />
Now if the checkbox isn’t checked it won’t get submitted, but the hidden input will, and if it is checked it will get submitted, but will appear after the hidden input with the same name. The result is that params[:the_checkbox] will be the string 'true' if it has been checked, and the string 'false' if it hasn’t. (Note that you may still have to convert the strings to booleans, depending on what you’re doing with the submitted data).
You could do something like this :
post '/your-route' do
params[:checkbox] ||= false
# now do whatever you want with params[:checkbox]
end
What this does is assign false to params[:checkbox] unless it is already defined and set to true.
I have a problem with a sfWidgetFormInputCheckbox. It do not save false in the database when the checkbox is unchecked.
In my schame my field is a boolean, and i don't have bug in the value displayed.
Set the default value like this : $this->setDefault('status', false); don't work either.
My widget :
$this->widgetSchema['SUSPENSION_TEMP'] = new sfWidgetFormInputCheckbox();
$this->validatorSchema['SUSPENSION_TEMP'] = new sfValidatorBoolean(array('required' => false));
The default :
$this->setDefault('SUSPENSION_TEMP', false);
Any ideas ?
Edit:
It save 1 when the checkbox is checked. And do not change the database value when you unchecked and save. So once you checked once, value is always 1 in database (true for my code).
Edit2:
I have two clues to add. If the field is an integer in the schema.xml, both values work, bu we got a poblem on value displayed (checkbox checked qih the 0 value). Here, he field is a boolean.
The setter receive two kinds of value, 'on' when checkbox is checked and true when it's not. I tried to set default value to false in form, and to overide he setter. Both don't work.
I mean the setter work, but for an unknown reason the basic seer is called right after with a wrong value.
Edit3:
Ok, i understand part of the problem. The setter is not called, when the checkbox is unchecked. I thought it was because, m code displayed a var_dump(). It was because later i copy the old version of this object in archive purpose.
But symfony should detect that the field has been rendered and it doesn't. I don't know why. I know why in html, but obviously symfony should be able to tell himself "hey, i add a checkbox here".
Is there an elegant way o do this, or should i checked it by hand ?
The problem came from my form handling. My legacy code, did no render all fields (ex : some stamp field, updated by a behavior). It was using fromArray, then save. This update only the fiels rendered.
The traditionnal symfony form, give null to all non-rendered fiels in order to chcuk for required validation.
So you need to check by yourself and set to 0, when you are using a fromArray then save. Still, i find the form->save really dumb, because you need to send useless(in this case) or confidentials data to your client in order to use it.
Okay, so I am uploading documents when a user registers on my site, I collect some personal information and save it. Now I have had a bit of a problem, I split up the main registration form into a couple of view, where the user once logged in can now edit certain information, like for example one field called personal_introduction. For some reason this wont save, even though there are no validation errors on the field. Messed around in the model, to try pick up the problem and fount THIS causes the problem:
'document_file' => array(
'checkuploadedit' =>array(
'rule' => array('checkUpload', false),
'message' => 'Please select your document.',
),
'checkuploadedit' => array(
'rule' => array('extension', array('doc', 'docx', 'txt', 'rtf')),
'message' => 'File extentions allowed: .doc .docx .txt .rtf - we do NOT accept pdf format.'
)
),
Once I remove this from my model, it saves the data. Now its weird for me that the main registration form gives no problems, and that this view that does not even contain a form input called "document_file" fails the save.
Any ideas...Please!!! Obviously I need to validate the upload.
I tried this: validation on a input file in cakephp , thinking that maybe the above code is not correct, still no luck.
Thanks in advance for your answers.
Cheers Louis.
I went on to further investigate the problem, and found the following, which I still cant explain. When submitting views that do not contain the upload form on the same model, it still tries to validate the upload form, I could actually see the value for one as if submitted, even though it was not. so the only solution I got was to go use unset($this->data['user']['document']) for the actions which do not have the document upload form field. Hope this makes sense.
I am using CHtml::checkBoxList for my form. For some reason I cannot use CHtml:activeCheckBoxList or CActiveForm::checkBoxList. Everything works fine only problem is that I loose checkbox values on form validation error. What could be the easiest way to fix this ?
If you're making a form, you probably want to use CActiveForm's checkboxlist, which is a form-specific wrapper of CHtml::activeCheckBoxList) instead. Something like
echo $form->checkBoxList(
$model,
'condiments',
array(
'ketchup'=>'Ketchup',
'mustard'=>'Mustard',
'relish'=>'Relish',
'onions'=>'Onions'
)
);
should give you a persistent check box list of hot dog condiments, for example.