Custom label text in cakephp - cakephp

I want to get two field values from a database table and combine them together and use that as the display text in the label. Also I want to make another field value in the table as the label id.
The AgeCat table stores the different age categories. The table definition is
age_cat_id ---> primary key
range_start
range_end
e.g:
age_cat_id=>1
range_start=>18
range_end=>24
What I want is to have the label text set as '"range_start" to "range_end"'
e.g: '18 to 24'
and the label id to be the age_cat_id.
What is the proper way to format the label text to display as above? I have retrieved all the records of the AgeCat table, and stored them in a string array ($agecats) using find(all). I'm having trouble retrieving values from that array and then format it according to above way and set as the label text. Please suggest if there is a better way to do this.
The purpose of this is to display each record in the AgeCat table following the format of 'range_start to range_end' but having their value set as the corresponding age_cat_id.
E.g: 18 to 24 is displayed using some form element but the value should be 1. It's like having a drop down list with custom strings, but each linked to a unique value. So once an option is selected, the value is passed, not the string.
If the label is not good enough, what form element is suitable for this?

Virtual fields:cakephp documentation.
public $virtualFields = array(
'cat_date' => 'CONCAT(AgeCat.range_start, " to ", AgeCat.range_end)'
);
P.S.: according to Cakephp conventions the primary key should be named id.
Edit: take a look there: form helper
echo $this->Form->select('id', $cat_date)
In the controller something like this:
$cat_date=$this->Model->find('list',array('fields'=>array('id','cat_name')));
with $cat_date an array containing the desired values in the select.

Related

Excel dropdown values depending on criteria

i'm trying to create a dropdown list that return the values of a big table if a certain criteria is true:
For example, in this example I need the dropdown to list all the names which city is "Bilbao".
If I create a sheet that "lists" all the posible dropdowns (one for each city with the names listed below), there's no problem. But I'm trying to don't use that sheet, I mean, that the dropdown directly calculates the correct list as an array and show it. That's because the real workbook has more than 100 "cities" that can change at any time.
Is it possible or maybe i'm overcomplicating that?
Regards!
You'll need to use a range that your filtered list of values appear in.
The formula =FILTER(Sheet1!$A$2:$A$11,Sheet1!$B$2:$B$11=Sheet1!$D$2) will return just those names that appear in the city shown in D2.
To use it in your data validation add a named range to the Name Manager (Formulas > Name Manager). My formula is in cell G2, so my named range looks at =Sheet1!$G$2# and is named CityFilter.
Now create your Data Validation to look at CityFilter.

How to fix MS Access Form Combobox error in VBA

I originally had my combobox cbSortOrder defined in the form as a fixed Value List. I am now attempting to set this in VBA code, using an array. I have tried with a variant and string array but do not think my issue is connected with that but is something to do with the combobox definition.
When attempting to set these values in a With statement, I get the Object Doesn't Support Method error.
I have attached screenprints of the actual error and properties of my combobox.
Unfortunately, you cannot use collections as row source in Access. A Row Source Type of Value List refers to a comma (or semicolon) separated text (depends on the list separator setting in Windows).
If you don't want to use such a value list, use a Row Source Type of Table/Query and specify a table or query name. You can also insert a SELECT statement directly into this field.
This also means, that you must store the entries in a table for this Row Source Type. You can also use a local table instead of a table in the back-end.
Also, the ComboBox has no List property. Use the RowSource property instead. In the code behind of the form you can omit the Forms("formName") part.
With cbSortOrder
.RowSourceType = "Table/Query"
.RowSource = "SELECT Id, Description FROM tlkpSortOrder ORDER BY Description"
End With
or
With cbSortOrder
.ColumnCount = 2 ' If you have and id and a text
.ColumnWidths = "0" ' Hides the Id column
.RowSourceType = "Value List"
.RowSource = "1,Ascending,2,Descending,3,Undefined"
End With
See also: ComboBox.RowSourceType property (Access)

Drupal, in a content type display some text depending on the value of a date field

I have a problem that puzzled me for quite a long time with the display of certain text depending on the value of a pair of date fields.
I have created a content type that includes two fields, a start date and an end date. I have also a third field titled "status" and I would like to make it display the values "in preparation", "in progress", "completed" depending on the value of the start/end dates.
Could you please guide me on how to do that?
I am using Drupal 7.
You can use template_preprocess_field and alter your field based on $vars['element']['#field_name'].
Also there is an $vars['element']['#object'] object that holds the original entity.

MsAccess - How to make an ID field fill in other fields in the form?

Problem:
I'm trying to make it so when a numerical field is filled in with a certain ID it fills in the other fields accordingly to what the first field was filled with. So if a person were to type in their ID it would populate it with their name accordingly.
Example:
But upon ID/numerical change I want it to do something like this:
Prior knowledge that may or may not help:
-I know this is possible with combo boxes but having a combo box with 2k-8k entries seems absurd
-I don't really think subform is optimal for this situation
-I think you can do this with "=DLookup" but I don't exactly understand how to pull it off
Please and thanks for any help. All is appreciated greatly!
Some built-in Access mechanisms:
Search field in the Navigation bar of the form.
Find feature (Ctrl-F).
Alternatively, with VBA you can use your own UI design and have more control:
Obtain the desired ID from the UI in whatever way you like - a textbox, a button and a popup, etc. Don't use a textbox that is bound to the actual ID field (ID fields should be read-only and you shouldn't use an edit field for a search field - keep them separate).
In VBA, obtain the ID that user searched for and then jump to that record using code like this:
Me.RecordsetClone.FindFirst "StudentID = " & studentID
If Not Me.RecordsetClone.NoMatch Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
You don't need VBA for this. Simply add the Student ID textbox value as a parameter the form's query and let it filter the results according the ID provided.
The query should be something like this:
PARAMETERS [Forms]![YourMainForm]![YourIdTextBoxName] Long;
SELECT *
FROM YourTableName
WHERE ((([Student ID])=[Forms]![YourMainForm]![YourIdTextBoxName]));
When you add a new ID, requery the form to see the results.
Me.Requery

Can I reference a field by name using a variable?

I can get a value from a .net data table that has columns named "Col1" and "Col2" like this:
DataTable dt = new DataTable()
// some more code that fills it
Console.Writeline("{0}, {1}", dt.Rows[0]["Col1"], dt.Rows[0]["Col2"]);
I could also use a variable if my datatable has a lot of columns
string x = // something that will be one of the columns in the table
dt.Rows[i][x] = "Some new value"
Is anything like this possible in NAV with a Record variable?
Well "like" this but not exactly. You can use RecordRef type to get reference to a field. But to interact with the certain field you will still need to adress it by its field number. You can iterate through all fields in the table and check their names to find the one you need. Not performant though.

Resources