I have a Angular App with a formgroup for something like a signup screen. There, I have all my inputs working like this:
<div id="form-group" class="left">
<input
[ngClass]="{ 'erros': groupForm.get('name').errors?.required && form.submitted }"
id="fullname"
formControlName="name"
class="form-control"
placeholder="Name">
</div>
It works flawlessly, but there is a specific field that never sends any data (the field is just like that one, but it is a select:
<div id="form-group" class="left">
<select formControlName="entity">
<option id = "zero" value="" disabled selected>Entity</option>
<option id = "_1" value=0 >CT</option>
<option id = "_2" value=1 >HP</option>
<option id = "_3" value=2 >CM</option>
</select>
</div>
). The funny thing is, when I console.log() this fromGroup, all my info is there (Even entity!). But is does not reach the Database (postgres btw). The API is Spring + Hibernate, and it has a model, resource and repository for every table in the db, their structure is like this:
Model:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "entity")
private Entity entity;
public GerProspect() {
super();
}
Repository:
public interface ProspectRepository extends JpaRepository<Prospect, Integer>{}
Resource:
@CrossOrigin("${origem-permitida}")
@RestController
public class ProspectResource {
@Autowired
private ProspectRepository ProspectRepository;
@GetMapping("/Prospect")
public List<Prospect> ListProspect(){
return ProspectRepository.findAll();
}
@GetMapping("/Prospect/{ProspectId}")
public Prospect editProspect(@PathVariable Integer ProspectId) {
return ProspectRepository.findById(ProspectId).get();
}
@PostMapping("/Prospect")
public Prospect addProspect(@RequestBody @Valid Prospect T) {
return ProspectRepository.save(T);
}
@DeleteMapping("/Prospect")
public Prospect remProspect(@RequestBody @Valid Prospect T) {
ProspectRepository.delete(T);
return ProspectRepository.findAll().stream().findAny().get();
}
}
I'm not the author of this API, but I need to use it anyway. All my info. in the formGroup is correct and not-null, but only the field Entity is never filled. I should also say that this specific field is a foreign Key with the same structure and this list<>:
@OneToMany(fetch = FetchType.LAZY, mappedBy = "ConfigEntity", targetEntity= Prospect.class)
List<Prospect> Prospects = new ArrayList<Prospect>();
I really dont know why, but this field is always null in the db. What am I doing wrong here?