Input field border in other color for NOT NULL fields - cakephp

I would like to have the input field border in another color if the underlying field is NOT NULL.
After studying the CakePHP documentation I think I can somehow implement it with the Custom Widgets but how do I get the information if the field is NULL or NOT NULL, or does CakePHP already offer something pre-build which I didn't find?
Update:
I display all tables in the edit mode with one script. With this I want to avoid 50 edit.php scripts serving each table in the database. In this one script I generate on the fly the edit form. This means, this script is NEVER assigned to exactly one table. This is not the problem as I can parse all fields and display them properly for every special database type [date, varchar, set, int, time, ...].
Even the field description is read automatically from the table field comment which is then displayed as title tag when the mouse is moved over the ? symbol.
And now, as the next step, I would like to show a different border for a input field which is NOT NULL. This means, the different border should be shown for all fields which are displayed for the table.
I am using CakePHP 4.1.4

I found this solution:
Due to the fact the function has to evaluate the table schema in order to generate on the fly the form, the function knows which fields are NOT NULL. Then, when it creates the field with $this->Form->control(..) it adds simple in the options argument ["style" => "border: color width type"] for these fields, which are NOT NULL..
If somebody has a more elegant way, please post it as an answer so I can learn something and I'll accept it.

Related

PowerApps LookUp with ComboBox to create DefaultSelectedItems

I am still quite new to PowerApps and I have run into a little problem.
I have a field, calibrator, of type person or group that an individual should fill in if they are filling out the form. So, what I did was auto-populate using Office365Users function to display the name of the users.
I then want to use the said field to fill out another field, Title, that should be auto-populated using a LookUp function to see if the calibrator is equal to another field assigned to, of type person or group. The function I used here was
LookUp(List, 'Assigned To' = DataCardValue.Selected.DisplayName, Title(of type single line of text)).
The issue I run into is when I auto-populate the Title field through DefaultSelectedItem, the LookUp function produces a Expected Table Value error. I am not sure what the reason for the error is, any help would be greatly appreciated!
Since you're using combobox, If you look carefully at the property it's DefaultSelectedItems.
So you need to use Filter instead Lookup hence the error saying Table Value is expected. Try this
Filter(List, 'Assigned To' = DataCardValue.Selected.DisplayName)
And if you want to display Title, you need to change DisplayFields property to
["Title"]

How do I get the SalesForce record id in a custom field

I wanted to add a simple read-only URL-field to 'opportunities' in SalesForce that contains a link to an external webpage with the 15-char record id (used in the salesforce urls) attached to it . To do this I wen to /ui/setup/Setup?setupid=Opportunity --> fields and created a new field under 'Opportunity Custom Fields & Relationships'.
I chose a field with data type 'URL' and added a default value. I thought
"http://example.com/?sfid="&id would do the trick, but this returns
Error: Field id may not be used in this type of formula
This is a vague error. Is my syntax of a default value wrong, or am i using the 'id' parameter in a wrong way? And what is the right way to do this?
I'm new to SalesForce, as you probably already have guessed.
As the other answer stated - Id will be known only after insert meaning the "default value" trick won't work for you.
You have some other options though:
Workflow rule that would be populating the URL field after save.
Formula field of type text that uses HYPERLINK function
HYPERLINK("http://example.com/?sfid=" & Id , "See " & Name & " in ext. system")
Custom link (similar to custom buttons, they appear on the bottom of the page layout. Search them in online help)
The difference between 2 and 3 is quite minor. Custom links can appear only on the record's detail view while formula fields & other urls are well... fields - so they can be used in reports, listviews etc.
You'd have to decide which version suits you best.
This is a great question. You're right, the error is very vague.
To begin with, read some of the documentation on default fields. Pay particular attention to the order of operations:
The user chooses to create a new record.
Default field value is executed.
Salesforce displays the edit page with the default field value pre-populated.
The user enters the fields for the new record.
The user saves the new record.
Default field values are calculated before any other record data including the id are available. For this reason, they cannot be calculated based on other record fields. Especially the record id, which has not yet been assigned.
To get this functionality, you will need to create a workflow rule that fires on record creation and inserts the proper value into your field.
It would be nice if we could have formula URL fields, but we don't. EDIT: I am dumb and forgot about using HYPERLINK in text formula fields, as eyescream correctly points out.

How can I get the ID of a record when it isn't mentioned on a form in Access 2007 via VBA?

I have a multiple items form which does not mention the ID of the record. I have a button for each row which, when clicked, opens up a new form containing more details.
In the past, I've added a field for the ID but made it invisible, but this seems silly - the ID is a unique field of the original query, so I should be able to access purely with code somehow.
Does anybody know how to do this? Let me know if you want more clarification.
Update
The fastest way for me to do this is to add a field in the form for the field in the query, call it the query field name, save it all and close it, then delete the field. Though of course I'd rather just be able to do Me.ID without any of that prior nonsense.
In some cases, you may have to refer to Me!ID, rather than Me.ID because the field has not been added as a property of the form (discussion: http://tek-tips.com/viewthread.cfm?qid=1127364 )
When you add the ID as as control and then delete it, it becomes a property of the form, which is why your work-around works.
If a form's record source includes a field named "ID", you can access the field's value as a property of the form:
Debug.Print Me.ID
That works without a control bound to the field.
you probably need to edit the recordsource / query.. and add that column as an available field.

CakePHP - Prevent model data being save in a saveMany call when certain fields are blank

I have scenario where I have 3 different models data being saved from one form, by means of the saveAll pass through method in CakePHP 2.x
The models on the form are:
Project
ProjectImage
ProjectAttachment
1 and 2 are saving perfectly, but I am having problems with the ProjectAttachment fields. If you look at the following image, the fields in question are at the bottom right, highlighted by a red frame: http://img.skitch.com/20120417-bnarwihc9mqm1b49cjy2bp13cf.jpg
Here is the situation:
I have named the fields as follows: *ProjectAttachment.0.project_id*, ProjectAttachment.0.name .... *ProjectAttachment.6.project_id* etc where the numbers are relative to the already present amount of attachments the user has added, as there is no limit. So if the user has ALREADY added 6 documents, the field would be called ProjectAttachment.7.id and so on. This is because of the naming convention when using the saveAll method.
I have made use of two hidden fields, one to store the user ID, the other to store the project ID.
The problem is that if the user does not fill in the Document Title and select a file to upload, the form fails! If I remove all validation rules, the form no longer fails BUT a blank ProjectAttachment record is inserted.
I suspect the problem may also be that the project_id and user_id fields (that are hidden) already have values in them?
I gave it some thought, and came up with a simple concept: In my controller, before the saveAll call, I would check to see if a blank Document Title field was submitted, and if so, I would completely eliminate the relevant array entry from the $this->request->data['ProjectAttachment'] array, but this did not seem to work.
To clarify, I am not looking for validation rules. If the user decides they only want to upload images and not touch the ProjectAttachment form, them the saveAll operation must not fail, it must simple not attempt to save the blank fields in the form, if this is at all possible.
Any suggestions?
Kind regards,
Simon
Well it seems that the solution was far simpler than I had initially thought! I was partially on the right track, and I had to unset the variable ProjectArray key in the $this->request->data array if I had encountered any blank fields.
I did this as follows:
if(!empty($this->request->data['ProjectAttachment'])){
foreach($this->request->data['ProjectAttachment'] as $key => $value){
if(is_array($value) && array_key_exists('upload_file', $value)){
if($value['upload_file']['name'] == ''){ // Blank document file
unset($this->request->data['ProjectAttachment']);
}
}
}
}
I hope someone finds this somehow useful in some form or another.
Kind regards,
Simon

Counting instances of a parameter value on an access form

I'd like to display, in the form footer of a Microsoft Access form, a count of a particular value of a field ("Category") I have tried using
=Sum(IIf([Category]="S",1,0))
as the control source for the text control in the footer, but this fails. I cannot figure out why I cannot perform this calculation on this control/field combination. I suspect it has to do with "Category" not being the control source for any control, even though it's available in the second column of my combo box.
I have performed the count on the "Appliance" field instead, and the sum function works correctly, So I'm pretty sure my general syntax and references aren't completely broken. Both underlying values are text fields.
I'd love some help with how I can get to the second parameter of the query with the Sum function?
Specifics:
ComboBox
Name is "lstAppliance". Bound Column: 1 , Row source :
SELECT qryApplianceDetails.Appliance, qryApplianceDetails.Category FROM qryApplianceDetails;
Text Box
Name is "txtCategory" , Control Source:
=Appliance.Column(1)
In case this isn't clear enough, what I'd like to see looks something like this:
Form header:
Appliance , Category
Form detail
Truck , S
Truck , L
Car , S
Bike , M
House, L
Planet , S
Form footer
Number of "S" things: 3
With this source in the footer:
=Sum(IIf([Appliance]="Truck",1,0))
Displays "2", as you would expect, but:
=Sum(IIf([Category]="S",1,0))
Displays "#error", instead of "3" as I'd expected.
I would try something simpler, but not sure if this will be too simple for what you need.
Use this expression as the control source for txtCategory:
=DCount("*", "qryApplianceDetails", "Category='S'")
Then in the form's On Current and After Update events, add this:
Me.txtCategory.Requery
In regard to the issue of using a field in the form's recordsource in an expression (or in VBA code), since A2000, things have become more difficult. It's not reliable if the field you're using has not been used as the ControlSource of a control on your form. The workaround is to create an invisible control with the field as its ControlSource.
Another way of working around that problem would be to create a control with this ControlSource:
=Val(IIf([Category]="S", 1, 0))
...then Sum() on that control.
I don't like the idea of using a DCount() as it requires a hit on the database for data that's already in the form. Secondly, if this is in a subform, the DCount() would need to be filtered not just on the Category value but also on whatever the link field is between the subform and its parent. It just gets so fussy that I'd say it's better to go with something that can be derived from the recordset already loaded in the form.

Resources