symfony - custom multiple checkbox widget - help - symfony1

I'm trying to create a custom multiple choice checkbox widget, that displays all items of a model.
My model is named 'Tag', which is a list of tags in my DB table.
I have copied the sfWidgetFormSelectCheckbox code and pasted it into my new widget class, but I'm unsure what to do next
Could someone help me?
Thanks

If your issue is working with tags. Best to look at sfDoctrineActAsTaggable. It should have all the behaviour you require, hence you should be able to dissect it to achieve what you are after.

I managed to get this working using some custom code, i.e. getters and setters and overriding the doUpdateObject() and updateDefaultsFromObject methods in my form class

Related

grails 2 Add new column to f:table

I would like to add a new column with some static values like buttons and links to an existing tag in a view.
Is this possible? In the documentation, I can only find how to add or removes attributes that are part of the domain class. There doesn't seem to be a way to add a column with custom values. Ex: a button with a link to the "show" view and so on.
Looks like (unfortunately) there isn't a standard Grails way to do this.
I did manage to do this by using tables and loops ... to run the loop and then displaying the values using Grails variables. It would be great though if there was a standard Grails way to do this as it seems to be waste to first use a framework and then discard the scaffolding to write your own custom table!

How to use same scripts in views

I have a view for creating an entity by filling a form. That form contains several inputs and 2 datatables table. i write a considerable amount of JavaScript code for initialization and validation of the inputs. For editing the entity, i need the 95% of inputs and JavaScript codes.
First, I tried to move the common codes to a partial view but some of them worked and some of it didn't work. For example the tables not initialized.
As a second approach, I can also write a lot of if-else to check the current page (between Create and Edit) and do proper action.
How can i have two views and common codes in both? Is there a better or functional approach?
save your javascript code as js file. Drag and drop its link where you want to use it :)
You can use the same view for Create and edit functionality.
And regarding the inputs, you can take one property in the model which will indicate whether to show or not to show that input on UI.
Model:
For eg. Public string displayInput=[none/block]
view:
You need to set the value of displayInput field properly when you want to show all fields and when you want to hide some fields.

Data access between parent and child custom-elements

I have a question that I have been unable to find a clear and concise answer to without extra unnecessary calls through Dart and Polymer.
I want to create a parent custom-element that is able to allow it's child objects to access the parents information.
Example:
If I create a container called Student-View that sets up some tabs and pulls the basic information. Then have a child element that is able to access much of the same information through {{firstname}} {{lastname}} etc...
I am not sure the best way to accomplish this, and would prefer if it were all self contained. Or, should I go the angular dart route. Thanks!
Your description is pretty vague. Do you mean something like this?
http://jsbin.com/kelub/5/edit
In this case, the parent binds the student record to the child element's student property, like so:
<student-worksheet student="{{student}}"></student-worksheet>

MVC Razor How to get the model in the Controller on HttpPost when the model is dynamic

I'm working a feature in the application where model will be dynamic in the sense that any settings data could be displayed and the view will get the model based on what tab they clicked on. I use Hidden field to store what the settings name was because they are same as model name. for ex., if tab1-> Settings1 then Model is Settings1[already exists in the Model].So I used # model dynamic in View and used #Html.EditotForModel() to draw the required UI based off the model. My problem is when I do HttpPost on Edit currently I'm using FormCollection to read the data on that page when I declare the model name in the param it will get it for me but I don't know which model is coming back other than by the Hidden variable and I need it because the Model validation is broken because of this issue. Any help or feedback is appreciated? I can give more details if required? Has anybody crossed this issue before??
Dynamics can be a good thing and a bad thing. Using them on models that have a common interface in a controlled manor is best.
There are different options that you can look at:
1)
Have you tried making the action method accept a dynamic type? That might be the easiest way.
You might have to set up a casting helper to cast the object to the correct type based on the hidden field.
2)
I have a similar idea in some code, but I created a viewmetamodel class that contained all my types as nullable properties. My action method accepts this viewmetamodel type and validates the properties that are not null.
In line with this, if your data is not too large, then you could load all the settings tabs and use Jquery apply the tab with on click.
3)
You could also create #sections or use EditorFor(c=>c.settings) for each tab. That way each tab will load a type safe object. You would need to create controllers for each.
I would say pick the easiest method for you. I hope that this at least gives you some ideas.

Can you change a custom attribute from a controller in ASP.NET MVC?

I am looking to have an attribute "show" on certain properties in my class and give the user the option to show other properties in the view.
Can I change a custom attribute from the front end?
Are you talking about the Filter attributes? If you are, you cannot change properties as they are statically defined, unless the code within the attribute happens to reference a static class or within the context at execution time, and then you pretty much can access within the attribute anything from that static or the context...
If I'm on the wrong track, please let me know.
HTH.
I am not sure attributes are the best approach for dynamically attaching metadata. Normally attributes are attached at code generation time.

Resources