in the yii framework
what is the difference between radioButtonList and activeRadioButtonList?
In Yii there is a "regular" and "active" version of (almost?) every CHtml form field helper/widget. With the "active" version you pass in the ActiveRecord Model and the Attribute you want to make a form field for. This ties the ActiveRecord model more closely to the form field which helps with a few things like:
applying the model->attribute's validation rules (especially ajax validation)
building the proper form $_POST structure for model->attribute assignments
getting the proper field label
etc
Use activeRadioButtonList if you are building a form for an ActiveRecord model, and use radioButtonList if you are building a regular form (for a CFormModel model).
Read more about the both versions of the radioButtonList helper here:
http://www.yiiframework.com/doc/api/CHtml#activeRadioButtonList-detail
http://www.yiiframework.com/doc/api/CHtml#radioButtonList-detail
radioButtonList not related to model
activeRadioButtonList related to model
Related
I have a model "behind" my page with a property that's a model of my search form. My form was working fine and then suddenly all the properties stopped binding and my Post action handler saw the search form model has having loads of nulls.
When you use Tag Helpers for a form and add input controls you can add your own name="myProperty" to each, or you can omit this and this attribute is auto-generated.
Imagine you have 10 inputs and you add a new one but forget to add a name attribute on this recent one, then the helper adds its own like "SearchForm.MyProperty".
The previous 10 end up with name="myProperty" but the last one is name="SearchForm.MyProperty".
In this situation model binding fails, presumably because these paths are mixed and the one matching SearchForm.MyProperty is more specific, making the others look like they should bind to properties on the page model.
Presumably when your supply your own names and they are all lacking the SearchForm. prefix then its smart enough to figure out to bind them all to SearchForm.
Fix could be not to supply your own name attributes to the inputs at all.
An improvement to Razor binding (to remove the surprise here) might be to always fail unless the names are prefixed accurately, though this would break existing code.
I am working on a custom sitefinity module in which I need to add a custom field where I can select a Sitefinity Form from a list of existing defined forms on the backend. What is the best approach to do this? Precisely how should I approach in defining the field and making its UI?
Unfortunately when I select "Related Data" as field type, Sitefinity Form is not available in the list of built-in data types. The other option (advanced option) I see is a GUID (or array of GUIDs) field type among field types which suggest making a custom code.
CMS version is Sitefinity 8.2 and we are using MVC-based feather components as well as our custom MVC components to develop the website.
Anybody had similar requirement and experience on this?
I would probably create a custom field control. This can be streamlined by using Sitefinity Thunder (because there's a lot of boilerplate C# and JavaScript needed). Once that's in place, you can create a custom field of either type Short Text or GUID, and for the interface, you use your custom field.
In your custom field's code, you can do something like creating a drop down list, where the text for each option is the form name, and the value is either the "name for developers" field or the ID of the form. That way the input is always constrained to IDs pointing to Sitefinity forms. Then when you interact with your custom content items later, you can use this ID/name to look up the referenced form.
As an aside about Related Data: Indeed, that only refers to either built-in content types (blogs, news, etc.) or custom-build dynamic content types. You won't find things like Forms in there.
I have all the controls (such as TextBox, Dropdown) saved in the Database which I have to render on the screen dynamically using some kind of loop. So, please suggest me the pros and cons of using Custom ASP.NET MVC 4 HTML Helper or Partial View. My DB Data model would be something like below.
Control Table
ControlID, ControlType, Value, LabelText.
Note: I can't change the architecture of having control data in the Database. So, please refrain from suggesting that :).
Thanks in Adavance!!
I am trying to implement a "Save as Draft" functioning in my project using Yii. I have a form with 2 buttons :- Submit and Save . On clicking the Submit button , after validating all the fields including required fields the form data is saved into the database. It works perfect. On clicking Save button I need to save the form data without default validations into the database. How can I implement this disabling of validation in a controller action ??
All advices are acceptable..
Thanks
Turning off validation rules all together is easy:
$model->save(false);
This will not do any validation and will just try and save your model (may still fail on the database side).
But if you want to run some validation ,you might want to look into Scenarios here. They allow you to specify a different set of rules depending on which scenario you initialize the model with. That way you can only turn on/off whole sets of validation rules.
$model = new Thingy();
$model->save(); // All default validation rules
$model = new Thingy('draft');
$model->save(); //Applies all default & "draft" validation rules
Your question says in Controller but as far as I know, in controller we have filters which do for example check the permissions. That can be overridden as explained in this section of the guide. If you meant the validation that is done in model, then you can use scenarios (bypass validation by binding rules to scenario and no validation in other scenarios).
Check this thread that discuss a like problem
If I have misunderstood your question please comment here so that I update the answer accordingly!
Something like this in application.rb:
# Configure application generators
config.app_generators do |g|
g.form_builder Formtastic::SemanticFormBuilder
end
If I do so I get an error when I try to scaffold a model:
Expected Thor class, got Formtastic::SemanticFormBuilder
Is it possible to set Formtastic as default form builder?
Updated.
I have tried Simple forms and it's really awesome (Thanks to nathanvda). The DSL is almost the same as Formtastic has. The only important difference for me is in customizing button labels. In formtastic it's possible to use resource file (formtastic.yml) to set different labels for the same model and action. Sometimes it's necessary, for example in Devise views. But it costs nothing to switch from formtastic to simple forms even in this case as it's possible to do it in this pretty simple way:
= f.submit t("customized_button_label")
Now about the original question. When I installed simple forms it creates template in lib/templates/haml/scaffold directory which will be used with scaffold. Straightforward.
I am not entirely sure about formtastic, either it does this straight out of the box, so not configuration needed; or not at all.
But what i do know: simple_form does provide scaffolding, even configurable which is totally awesome. The DSL between formtastic and simple_form is close to identical, but with simple_form the level of configuration is much better. You have total control how a form should be scaffolded, you have total control how a single field is turned into html. Pretty awesome.
You can find a quick introduction here.