firebase three-way binding and ng-bind-html - angularjs

I'm creating a simple admin interface where an authenticated user is able to edit parts of a site, using firebase three-way binding (I'm using angularfire).
To be as user friendly as possible i at least want to allow them to have line breaks. Therefore i use ng-bind-html, but the problem is that real time validation will throw tons of errors until the entered html is valid (which is understandable).
I was wondering if this approach is even considered OK, or should i think differently. For example only update the view value once the user has finished typing, or create a button that would insert line breaks? Or maybe a filter that would return /n as <br>?
What are your experiences, suggestions? I dont really need html, the most i need is just line breaks.

Related

How to save a recordset without overwritting existing records with Cakephp 3

Is there an easy way to save a recordset, i mean multiple records, but only the "new ones"?
I have a table users and a users form in the view. First field you must enter is passport number, so if user already exists in database the rest of the form will be auto completed and disabled to prevent changes but if passport dont exist then you have to enter all data. As anyone can change those existing users data controls from the browser even if they are disabled, i want to make sure only new records are saved in database. First of all i thought i could find again in database and delete existing users from recordset before save, but i wonder if there is a more elegant approach.
Ty in advance.
I write this here, cause comments are too short:
Thank you for your answer, André. I'm sorry if i didnt explain perfectly, but the form is done by disabling all controls except passport and if passport dont exist (i check it on passport focusout) then the rest of controls are set to enabled. I mean, that is already done. The question was only about the saving.
The validation method you talk about, well i'm actually validating all the controls in the form and i must disable the 'unique' rule so a user can link an existing user to the current bill, otherwise it will fail validation on submit and it wont allow the user to proceed (i did this because it happened to me when testing). The actual setting is much more complicated: the form belongs to a model (bills) which is associated with 4 other models and 2 of those relationships are many to many, bills_users and bills_clients, where users are the persons who do the job and clients pay for it, but I was trying to make the question easier. Anyway, what I am looking for is, in fact, some kind of saving setting which I can't find. In documentation I found "When converting belongsToMany data, you can disable the new entity creation, by using the onlyIds option. When enabled, this option restricts belongsToMany marshalling to only use the _ids key and ignore all other data." The first half of the sentence was promising, but the explanation says different, and I actually tried it without success.
First:
Is there an easy way to save a recordset, i mean multiple records, but only the "new ones"?
Yes there is you can validate it in model, something like this:
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->isUnique('passportNumber'));
return $rules;
}
This will prevent to save a duplicate passport number register, but you can different.
I have a table users and a users form in the view. First field you must enter is passport number, so if user already exists in database the rest of the form will be auto completed and disabled to prevent changes but if passport dont exist then you have to enter all data.
There is two different ways to do this:
First you have your form, you develop an ajax function when you fill the first field (passport number) this ajax function do a request to your controller to search for a passport with that number if find something get data and fill others fields and turn them just readable, else just nothing and let user fill the fields by himself
second add a step-by-step where you first do a form to try find by pass number, user fill this only field with a number then submit, on submit this search for a record, if find fill the entire next step fields, else the next step will be the rest of form with the fields to be filled.
This may help you too: https://book.cakephp.org/3.0/en/orm/validation.html
Tell me how you decided to do :)

How do I make it so that a user must either enter text or select a check box on Salesforce?

I am using salesforce for a group project here at SJSU, the thing is this is our first time using it, and we are having a little bit of trouble programming some things on Salesforce.
What we are trying to do:
We have a section on one of our forms where users will give us authorization to use Data they submit, the usage of this data will be under the terms set by those who submit the data. If the user does not want to set limitations on their authorization for us to use the data then they can select a checkbox called labeled "none" which basically means they are setting no limitations on what we can use their data for.
What we want to do is, if users select the checkbox then we want the users to not be able to enter any text into the textbox. If users enter text into the box while the checkbox is checked we want an error message to appear which will let the user know that no data can be entered into the box if the checkbox is checked. However if no checkbox is checked then we want users to be able to enter the data. How do we go about doing this
AND (None_c = True then Limitations_c has to be empty, elseif None_c = False then Limitations_c cannot be empty.)
If you want to leverage the out of the box UI (Page Layout), then you will likely want to use Validation Rules.
https://help.salesforce.com/HTViewHelpDoc?id=fields_defining_field_validation_rules.htm&language=en_US
The gist of it is that you want to define Error criteria, so when this criteria evaluates to true, and error is thrown. In that case, you should be able to construct something similar to the following:
Checkbox1__c && NOT(ISBLANK(Text2__c))
Validation rules would be the easiest way to execute this, though checking the box would not dynamically prevent users from entering text. With a validation rule, it just wouldn't let a users save.
The nice thing about using validation rules is that you can construct them such that checking None__c will not vomit on the user unless they actually modify Limitations__c. ISCHANGED() is great for that.
If I could suggest an alternative, the way I would implement this is to treat an empty Limitations__c as None__c = True. It simplifies things for users, and you can add a formula-driven checkbox if a checkbox element is truly required.

Want to display results of a callout

When a user 'Saves' a Contact (for example), whether it's new or just updated, I need to:
Do an external callout using one of the Contact field values as a lookup
Display the results of the callout, so the user can make a selection
Update the Contact based on the user's selection display the updated Contact
I have found two aproaches, but have reached a point in both that I need to resolve.
Trigger Based Method
In the 'after' trigger pass the lookup string to a callback.
Update the Contact with the selection
Issues
How do you pass the lookup string or results to a visualforce page to display the lookup results?
When the user makes the selection and the update has been done, how do I move back to the updated contact?
Override Base Method
I found a discussion here that seems to suggests using overriding & redirection to someone asking about 'Edit'. I think this could also be done with the 'Save' button.
Issue
This is meant to be a deployable sollution, so I think that the override has to be set in code (I'm using the IDE) and not via Setup (or am I wrong?). I can't find out if this is possible or how to do it
Sorry for detailed question. Didn't want to just ask the wrong question (i.e. assume I know the best approach).
Thanks...
For the trigger-based method, you cannot change the built-in Save functionality, but (per your second solution) you can override the Edit button and recreate the Edit page with Visualforce, which would give you full control over the Save button and how you handle the callout and redirecting.
The release notes for Spring '10 indicate that standard-button overrides are now available for packaging, as they can be created through the Metadata API.

Making Related Models Optional

I have a form where a user can enter a location address as well as the utility companies that provide service to that address. The Utility data is associated to the building:
Location hasMany Utility
Solely within the context of the utility, the name field is required so there's validation indicating as much. Within the context of a location, though, any utility information is optional. The user can choose not to enter that data when entering a location which would simply indicate that they don't want to associate the location with any or all of the utility companies we track.
Using the FormHelper, though, the validation is detected and the field gets marked as required. I want to retain that validation for the instances where utility data is being entered independently, but remove the required indicator on the location form.
I know I can hack this in any number of ways (e.g. removing the required class via javascript, etc.), but I'm wondering if there's a clean way to do this using the Cake API. I haven't seen anything obvious, so I'm hoping someone else has been here and found a clean, simple solution.
Thanks.
You can either ask the user how many utilities they want to add before creating the form, or you can add the Utility record inputs dynamically using js (the later is more work to do, and not as error-proof as the former).
An example of the view (if you want to do it in 1 view):
if (empty($this->data){
// a form to ask how many utility records the users want to create.
}else{
// generate the form based on user input.
}
I assume you know what to do in the controller.
I would add a class to the form element that are optionnal, and use that class to override the "required" indicator.
In fact there is a Cake solution, use the error param
$this->Form->input('Model.field', array('error' => false));
To disable error message output set the error key to false.

Cognos : Persisting Checkbox state across Multiple Pages

On the Cognos Report Results Page, we need to have a checkbox for each row.
The checkbox is designed using HTMLITEM tag.
However, the problem we face is that the state of the checkbox (checked or unchecked) is not persisted when we go to the next page/previous page.
I am very new to Cognos and I need to know if there is a way to do this.
I am fairly good at JAVAScripting and JSP, but since we only have access to HTML elements and not JSP Tags (Cognos uses CGI anyways), I cannot get the request object.
If there is some way to retrieve the request objects parameters of previous submit(previous page), that would help in solving the issue to a large extent, I feel.
Jonas
There isn't really enough information on what your end goal is to be able to assist you with this properly. There are a few ways that spring to mind that would allow you to use JS on the report to remember previously checked items, but there may be a much better way to do this depending on your requirements.
Without having more details, the first thing that leaps to mind is simply having some JavaScript set and unset cookie values on check/uncheck on the checkbox.
Note, there could be a variety of other ways to work this, including upping the number of visible rows per page, etc...
You can create a dataitem in a query where you can determine whether your checkbox should be checked or not. In the design of your list on the report page you can render a HTMLItem within the list, and base the HTMLItem on a DataItem. Your HTML must than be something like
<input type="checkbox" value="""+ [DataItemValueToPass] + """ " + [DataItemCheckedOrNot] ></input>

Resources