Symfony forms ChoiceType how to add new choices from user's input - symfony

I am using js library that allows user to add new values into html select element but I cannot find a way handing that new values from symfony side and dynamically add new option.
As one of the solutions I was trying to use 'choice_loader' options with default ChoiceType field and implementing ChoiceLoaderInterface like in this post but there should be a simpler way.

I don't think you can do it in an other way with a ChoiceType but maybe you can create you own custom type :
You can create your select element by customize your form rendering or/and default classes set in your custom FormType.
You can use a ModelTransformer in order to retrieve your existing values and create new ones
You can use a simple TextType in inheritance format the data send by the form with a delimiter and create a ViewTransformer in order to retrieve a collection on the other side

Related

Add a search field by header using PeopleSoft

I’m looking to add search fields in each table header automatically using peoplesoft.
Example
Javascript solution:
add an html area to your page (with rec field)
assign via peoplecode an html object to the field
use something like this Javascript Filter on the table
For this to work well, your grid needs to show all rows and not paginate.
If it paginates and you need to keep the pagination, then you need to go for the PS solution:
Add one search field per header you want to search
On the fieldchange you perform a rowset flush then .Select(" WHERE ...") to populate it based on the filter

Is it possible to create a variable in google tag manager that refers to form name?

I am trying to create a trigger for a particular form. What is the correct way to refer to form if i have no id?
Untested, but you should be able to create a DOM type variable, change the selection method from the default "id" to "CSS selector" and use that to address the form in question:
The actual selector might need a bit tweaking (and obviously you'd want to substitute the real name of the form in the square brackets), but basically that is the way to go.
You then create a form submit trigger, set it to "fire on some forms" and use the variable created above to filter the trigger for that specific form.

How to show wordpress setting api validation error message?

I have created a setting api for my new plugin. It has four <input> field and one <select> option. In that field , user can change value according to their requirement. But it must be valid value. Suppose , one <input> field support only integer value. so when user will fill that <input> field by string or by other things, it will show an error message. Please tell me how can i do that? Can you suggest any tutorial ?
When using add_setting you can pass a sanitize_callback option as part of the array, this can contain the name of a function that is run which can contain your validation.
A similar method exists for JavaScript too, which you could use to validate the fields as well.
You asked for a tutorial too, here is one that outlines the method I've described: http://themeshaper.com/2013/04/29/validation-sanitization-in-customizer/

Entity reference field and dependent dropdown

I have a content type with an entity reference field referencing to a custom entity. I need to use a select box because an autocomplete widget is not suitable in my case. However, I cannot load all the entities at once as selectable values because they are too many (72000+ the form won't even load). So I default the entity reference select box to a limited number of values using a views filter and then hide it by default. Then I use an ajax dependent dropdown to show and populate the entity reference select box with filtered down values (I'm using a module that implements hook_form_alter).
My problem is that the form won't validate because now I can select entity reference values which are not the default ones in the select box. So I guess I should control in some way the validation rules of the entity reference field. Is there an easy way to do this? Which hook should I use?
Set the entity reference field to autocomplete and take it out of the process entirely in your form alter with $form['field_entity_ref']['#access'] = FALSE. This should fix the validation problem. (of course, "field_entity_ref" is what I'm calling your actual reference field.
Add your own validation to the form, if that is still necessary.
Finally, implement hook_node_presave() to manually put the value of your custom ajax drop down box.
So if your custom ajax select box was named my_custom_ref, then it would look something like this:
function mymodule_node_presave($node) {
if (isset($node->my_custom_ref)) {
$node->field_entity_ref[$node->language][0]['target_id'] = $node->my_custom_ref;
}
}

Is it possible for a behavior to specify a custom subform for fields which it adds

I'm trying to create a behavior which adds 2 new fields to content types to which it is applied, but I'd like those fields to have a custom subform on the add/edit forms for content types it is added to. Is there any straightforward way to do this as part of the behavior?
You can use a fieldset inside your schema
from plone.directives import form
....
class IMyBehaviorSchema(form.Schema):
form.fieldset('myfieldset', label=u"My Behavior fieldset",
fields=['firstfieldname', 'secondfieldname'])
to display your additional fields with Plone form tabbing enabled. See Dexterity manual for further information

Resources