f:form.select does not show me the data - typo3

I have an object adherent that contains an object grade(Class: Grade, membres: $uid,$abelGrade). I want to display all grades in database table 'grade'. so I assign a grades (an array of grades) to my view and i write this code :
<f:form.select property="grade" value="{adherent.grade.labelGrade}" options="{grades}" optionValueField="uid" optionLabelField="labelGrade" size="1" id="category" />
but the problem it doesn't display anything. what could be the problem?

The problem could be missing $grade->getUid() and $grade->getLabelGrade() methods. These are called due to the optionValueField and optionLabelField. If thats not the problem, set a breakpoint where you assign the {grades} array to the view and check if it's really an array or an ObjectStorage. Thats everything I can think of right now, maybe you'd like to provide some further code.

Related

Mixing and aligning non-Smart fields in a SAPUI 5 Smartform

The attached screen below works just fine but underneath the covers I have a slight problem ^^
Smartform with both simple and smart fields
Behind the view there's a smartform (no annotations used). Field "Agreement Action Type" and the last two pairs of fields are not smartfields (found no "smartcombo" or something similar to use) they are just pairs of labels and comboboxes and here comes the issue. While the smart fields were all perfectly aligned, comboboxes (aka simple fields I suppose) were not aligned along. In order to solve this for the moment, I used a couple of SAPUI5 formatting classes and...width declaration in pixels in the combo definition within the view. Results works fine, even in different size monitors but, even though I'm currently in the process of learning and understanding the technology, I already know that the latter is a crime against SAPUI5. Is there a way to align smart and simple fields in the same view (or an equivalent dropdown control for smartforms alternatively) or I will have eventually to get rid of my smartform (losing small bonuses like the togglable attribute) and use a simple form instead?
Thanks for taking time to read it.
Regards,
Greg
The GroupElement aggregation manages the SmartLabel for you so try to remove the label inside the GroupElement aggregation like this:
<smartForm:GroupElement label="Label">
<Input type="Text" value="someValue"/>
</smartForm:GroupElement>
On the contrary, if you want to change the appearence of your SmartField, you can use ControlType to configure the internal control.

Properties that were not listed in fluid-form overwritten after submit

In my extbase 6.2 extension (built with extension builder) I have:
An appointment that has
a lawyer that has
specializations (called expertises in this example).
In my form I simply want to edit the expertises, but every time I hit submit my lawyer's properties are emptied except for the expertises - those work, even their values are correct.
When I debug the object in fluid the lawyer is there and everything is correct.
This is the only place in my fluid form where I wrote the word "lawyer".
<f:for each="{appointment.lawyer.expertises}" as="expertise" iteration="i">
<f:form.checkbox property="lawyer.expertises.{i.index}.checked" value="1"/>
<f:for each="{expertise.subExpertises}" as="subExpertise" iteration="j">
<f:form.checkbox property="lawyer.expertises.{i.index}.subExpertises.{j.index}.checked" value="1"/>
</f:for>
</f:for>
Usually my properties of appointment don't get overwritten just because I don't write a form input-field for them.
So why are the properties of appointment.lawyer overwritten and how can I keep this from happening?
Unfortunately I have no idea what TYPO3 is doing in order to build an object from my form so any hints on that would be appreciated too :)
It is not that easy to edit the properties of related elements.
What TYPO3 does in your case is that the original related lawyer record (and also the original expertises) is detached from the appointment object and a new one is created instead, that is why you think the other properties are emptied. You will also see that, if you look up your elements in the list view, there will be more and more each time you save it. The reason is that the form is not automatically generated with the lawyer's and expertises's uids so TYPO3 thinks that these are new objects.
There is one solution I know (if someone knows a better one, please share) But you need to read the whole description:
You have to manually add the uid field in your form for every related object. Assuming that your form has name="appointment"
<f:form.hidden name="appointment[lawyer][__identity]" value="{appointment.lawyer.uid}" />
<f:form.hidden name="appointment[lawyer][expertises][{i.index}][__identity]" value="{expertise.uid}"/>
You will also have to do it for the subproperties.
Important!
That way the user can also manipulate the ids and modify the objects that he is not supposed to have access to, so you have to check the relations before saving. For that you can use the _getCleanProperty('xx') method of a domain object to get the original data of it.
if ($appointment->getLawyer()->getUid() != $appointment->_getCleanProperty('lawyer')->getUid()) {
die('error');
}
You need to check all the relations that can be manipulated that way of course.

How can I pull data in a controller and form for one model that is in a different model with out a foreign key relationship?

I am new to rails and haven't really done to much with data outside of the model.
I have a form that references a table controller for files. I want to add an dropdown that will display a list of projects from a project table for the user to assign a the file to a project if they want too. Assigning a project is not a requirement. The file can be unassigned to a project. I do have a project_id column in the file table for those projects assigned but it is allowed to be null and I did not build a relationship because I need to have cases where there are none.
Can someone please tell me how to do this?
When they evaluate the file, the screen posts back with a save or update button depending if it has already been saved in the database.
At the same time as the save and update pop up on the right I want to display a list box of the projects with an assign project button. If new just a list, if update either just a list because not assigned or display the selected value in the list if already assigned, while allowing them to change it from the list if desired.
In the file controller method that posts back to the UI I have this code:
#file_alias_filedata = FileAliasFiledata.all
#projects = Project.all
for update
#projects = Project.find(params[:id])
In the form I have this code:
<p> <label> Select Project to Assign:</label> <br />
<%= select_tag 'projects', (#projects.present? ? options_for_select(#projects, #selected_project) : []) %> </p>
The form runs but I get this in the dropdown box:
#<Project:0x))7ff531ab4518>
Can someone please help me figure out how to accomplish my task and why I see the strange box value?
What am I doing wrong?
Thank you for your help!
Assigning a project is not a requirement. The file can be unassigned
to a project. I do have a project_id column in the file table for
those projects assigned but it is allowed to be null
From the docs:
belongs_to(name, scope = nil, options = {}) public
Specifies a
one-to-one association with another class. This method should only be
used if this class contains the foreign key. If the other class
contains the foreign key, then you should use has_one instead. See
also ActiveRecord::Associations::ClassMethods’s overview on when to
use has_one and when to use belongs_to.
Methods will be added for retrieval and query for a single associated
object, for which this object holds an id:
association(force_reload = false)
Returns the associated object. nil is returned if none is found.
Likewise,
has_many(name, scope = nil, options = {}, &extension) public
Specifies
a one-to-many association. The following methods for retrieval and
query of collections of associated objects will be added:
collection(force_reload = false) Returns an array of all the
associated objects. An empty array is returned if none are found.
But belongs_to() and has_many() are supposed to make things more convenient for you. You certainly do not have to use them.
Next,
and why I see the strange box value? What am I doing wrong?
You see the strange value for the same reason the following two loops display different things:
class Dog
attr_reader :name
def initialize(name)
#name = name
end
end
#dogs = [
Dog.new("Sam"),
Dog.new("Betty"),
Dog.new("Pete"),
]
#dogs.each {|dog| puts dog}
#dog_names = #dogs.map {|dog| dog.name }
#dog_names.each {|dog_name| puts dog_name}
--output:--
#<Dog:0x0000010099a308>
#<Dog:0x0000010099a2b8>
#<Dog:0x0000010099a268>
Sam
Betty
Pete
You will see the same result if you do something like the following in a view:
<div>
<%= select_tag "dog", options_for_select(#dogs) %>
</div>
<div>
<%= select_tag "dog_name", options_for_select(#dog_names) %>
</div>
If you read the docs here:
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select
...you will see several examples, which should make it clear that options_for_select() takes an argument that is:
An array of Strings.
A Hash where both the keys and values are Strings.
An enumerable that iterates over some Strings.
etc.
Do you see a pattern? It's Strings! options_for_select() needs an argument that consists of Strings. If the argument is not a collection of Strings, e.g. an array of project objects, then options_for_select() tries to convert the objects to strings by calling to_s() on the objects. And the default to_s() method is Object#to_s() which is inherited by all objects and produces a string containing the class name and the object_id.
I am also new to rails, but I think you can try using the options_from_collection_for_select method.
<%= select_tag :search_state, options_from_collection_for_select(State.find(:all, :select => :name), :name, :name) %>
Hope this help. Cause it certainly helped me.

Commonspot forms hidden field values

I have a form in commonspot, which uses hidden field to pass the information to next form,which it got from a previous form, but I'm not sure about the syntax for the default value of hidden fields. I have tried using form.fieldname, evaluate(form.fieldname), and #form.filedname#.
Can anyone help me with this ?
Thanks,
AA
Ardash - you should paste some actual code to help us understand what you mean.
In general if you want a "default" value (for the case where the item doesn't exist previously) you should use cfparam like so:
<cfparam name="form.myField" default="*some default value*"/>
Then in your hidden field you can safely do this:
<input type="hidden" name="myField" value="<cfoutput>#form.myField#</cfoutput>"/>
Hope this helps. Paste some code for a better response :)
You can list the field names submitted to the page using this method:
<cfoutput>#form.fieldnames#</cfoutput>
alternatively, you can get the field names and data:
<cfdump var="#form#">
This might help you figure out what is going on.

cakephp empty option for select fields

I am stumped beyond belief.
I have a select box being generated by the cakephp form helper. I am feeding it an array of options, and passing an empty value... pretty standard stuff.
However, my "empty" field is showing up at the very bottom of the list.. not the top. So when the field loads, it just defaults to the first option... which is not the "empty" option.
Not a whole lot of room for error on the code here..
echo $this->Form->input('whatever',array('empty'=>'Choose One','options'=>$categories));
The only small item that might be important, is that $categories is a multi-array, so the select box has optgroups & options.
Is there some quirk/bug out there that I do not know of that is trying to force me to sneak into my scotch supply a few hours ahead of schedule?
edit: using the latest release of cakephp 1.3.x
I think that I once had the same problem.
It turned out to be the data (options array).
Is there an option with an empty key? probably the last one then.
this lead to the scenario I remember and seems to be the exact same thing.
the form helper will override this empty key value pair then and not create a second one.
without more infos from your end this will be difficult to solve.