AngularJS Dynamic email validation element, When I fill out the email check element, It's reset - angularjs

I would like to create a form with several fields: name, last name, ... and add one or several email. The user should enter the first mandatory email address. After he should have the possibility to click on "Add email" for adding a new email address. He could add 4 others emails.
The system should be verify if the format is correct and register the data in a DB.
Could you tell me which is the best practice for doing that?
Kind Regards,

In the Database:
You should have separate table for storing email address's with foreign key that will be pointing to the main table
Table structure will look like this
ID,Email,Foreign-Key ID
In the Service layer you should have model class that will take email as array parameter
email class
class Email {
public int id,
public string email
}
in the main class
class Main {
email:Email[]
}
in the front end
you should clone the input type whenever the add email button is clicked and push the new element to an array and send it to the service layer

Related

Laravel multiple user id tables

I'm pretty new to laravel and have a really basic question related to relationships.
Here is an example of my question:
I have a migration called money_transfers.
The migration contains the following things:
user_id (transfer sent by)
sentTo_id (transfer sent to)
amount
sent_at
BOTH user_id and sentTo_id refer to a User ID.
Now, what I want to do is the following:
Fetch the user the money was sent TO the same way as the user the money was sent BY. Just like in the example below:
$transfer->sentTo->name
or
$transfer->sentTo->id
You get what I mean. Thanks in advance :)
If you defined your foreign keys correctly in your migration table, Then it's just a matter of defining the right relationship:
class MoneyTransfer extends Model
{
public function sentBy()
{
return $this->belongsTo(User::class,'user_id');
}
public function sentTo()
{
return $this->belongsTo(User::class,'sentTo_id');
}
}
This way you can access the receiver attribute like this:
$transfer->sentTo->name;
And the sender attribute like this:
$transfer->sentBy->name;

Grails 3 scaffold rendering dropdown list for domains with foreigh keys

If I have the following domain using Grails 3
class Books {
String Title
String Description
Author author
}
The generated scaffold create a dropdown list for author, which is good however, the values on the list contains;
webapp.author : 1
webapp.author : 2
webapp.author : 3
How can I make it display a field in the author domain, like author name and last name and remove project name, domain name and the id?
You need to add this to you Author Domain
String toString() {
"${AuthorName}"
}
Change AuthorName to the actual variable you want displayed on the dropdown list.

How can we reverse the functionality to copy billing Address to shipping Address in Account object?

Actually there was an existed functionality to copy billing Address to shipping Address in Account object. But i want to create a button so that shipping address have to copy into billing address.
You can create page and controller and call them from the button
public with sharing class CopyBilling {
string accId;
public CopyBilling (){
accId = ApexPages.currentPage().getParameters().get('accId');
}
public PageReference copy(){
Account acc = ...
return new PageReference('/'+acc.Id)
}
}
<apex:page controller="CopyBilling" action="{!copy}"></apex:page>
I implemented a custom check box field and workflow field update. Slightly more rudimentary, but it works.
Create a custom checkbox 'copy shipping to billing' on the account object.
Create immediate workflow actions of 'field update' for each field you want copied over. Select 'Use a formula to set the new value' and insert the corresponding shipping address field for each field update.
On save, the record with replace the billing fields with the shipping fields.

getting Value of a field by its Name in apex salesforce

in my visualforce page i have some campaign object first user select an object then there is a multi picklist. in this picklist there is Label for all the fields user selects some fields then i have to show the value of these fields in the selected campaign object
for showing multiple picklist my apex function is
public List<SelectOption> getOptionalFields(){
Map <String, Schema.SObjectField> fieldMap= Campaign.sObjectType.getDescribe().fields.getMap();
List<SelectOption> fieldsName =new List<SelectOption>();
for(Schema.SObjectField sfield : fieldMap.Values())
{
schema.describefieldresult dfield = sfield.getDescribe();
fieldsName.add(new SelectOption(dfield.getName(),dfield.getLabel()));
}
but i have no idea how to show value for the the field
for exmple i have object instance like
Campaign c;
now i have to get value of any field whose Name is in string form.how to get corresponding value for that field.one solution is just write like
say
String fieldName;
and use multiple if
if(fieldName=='Name')
c.Name=
if(fieldName=='Id')
c.Id=
is there any other convenient method??please explain!!
You need to read about "dynamic apex". Every "concrete" sObject (like Account, Contact, custom objects) can be cast down to generic sObject (or you can use the methods directly).
Object o = c.get(fieldName);
String returnValue = String.valueOf(o);
There are some useful examples on dynamic get and set methods on Salesforce-dedicated site: https://salesforce.stackexchange.com/questions/8325/retrieving-value-using-dynamic-soql https://salesforce.stackexchange.com/questions/4193/update-a-records-using-generic-fields (second question is a bit more advanced)
You'll still need to somehow decide when to return it as String, when as number, when as date... Just experiment with it and either do some simple mapping or use describe methods to learn the actual field type...

JSF - How to use database row values to generate additional columns in datatable

I have a problem which should be easy but I have trouble with finding the solution. I have a database that I want to present in a datatable. However I need additional columns that get more information about the current row. For example - the database has a set of people with id numbers. What I need is to display the Name, Last Name, ID (all columns of database), but then I want to display the address which is in a different REST webservice and to get it I need to send the ID (from database). I hope I have described it clearly but just in case I will point out:
-my database has 3 columns: name, las name, id number
-I need to add a 4th column to my datatable with address
-to get the address I need to send the id number to a rest webservice
The only solution I was able to find so far i to add all database elements to a list or some container and then use it inside a bean. But that is unacceptable since the database is very big. There must be a simpler way but it seems that I can't form an adequate question for google to get the proper results :> Can any one give some advice?
So what you basically want is to do a join between the result of a query to a database and the webservice.
Of course you don't need to load the entire DB in some bean to do this "join", just load the data you would like to display on screen in a backing bean, load the addresses for each row, and bind the result to the datatable.
Something like this:
#ManagedBean
#ViewScoped
public class MyBean {
#EJB
private someDataService;
#EJB
private someWebService;
List<Person> persons;
Map<Long, String> addresses;
#PostConstruct
public void retrieveData() {
persons = someDataService.getByID(someID);
for (Person person : persons) {
addresses.put(person.getID(), someWebService.getByID(person.getID));
}
}
// getters here
}
And the Facelet:
<h:dataTable value="#{myBean.persons}" var="person">
<h:column>
#{person.name}
</h:column>
<h:column>
#{person.lastName}
</h:column>
<h:column>
#{myBean.addresses[person.ID]}
</h:column>
</h:dataTable>
There are some choices to be made. You could also do the joining inside a single service and have it return some type that includes the address. You could also make a wrapper or a decorator.
It would also be more efficient if the web service could handle a list of IDs instead of requiring a separate call for each address fetched. You might also wanna do some local caching, etc, but those details are up to you ;)

Resources