49
Views
10
Comments
Solved
Change the enable property of a button in a table dynamically
Question
Application Type
Reactive

Hello everybody!  

I'm developing an application that allows users to apply for ongoing contests.  

I have a home screen that has two tables, one with ongoing contests and another with the candidacies of the authenticated user.  

I added a column with a button in the first table that allows the user to apply for the contest if he hasn't already done it, for the specific contest of that table row.  

My question is how can I change the value of the enable property of the button, based on the result of a server action that I have already created and which, based on the ContestId and the CandidateId, returns a boolean that indicates whether or not the user can apply . 

Fetch data from other sources does not allow passing any parameters, which would be the ContestId of each table row. Also, I cannot use a client action because it does not allow any return value. I also considered using the table's aggregate, but putting the logic of whether or not it is possible to apply in a new attribute would not be easy.

   Thanks in advance! 

UserImage.jpg
Craig Rodrigues
Solution

@João Neto Dear João , please find the attached oml. Not really sure if this is what you want. 
A basic explanation about the code adhering to same database design 
1)You'll need two aggregates to achieve as there is nothing in common between contest and candidates because the user id is stored else.  (Could have been easier if the user id was stored in the candidacy table other then extended the user  table)
2)You'll need a calculated attribute in the main aggregate which is false and then second aggregate which is called on demand.
3)After fetching records from the main aggregate launch an event to check if the logged in user is already a contestant for the particular contest and change the calculated attribute accordingly.

So to obtain the end results you wanted , this would be implementation based on your database design and question ,but I would recommend to verify this again to adhere to the best practices.


Contest.oml
UserImage.jpg
João Neto

Hello! 

Thank you very much for the answer, it was exactly what I was looking for. 

I already had a way of getting the data I needed, I just wasn't able to understand how to put the two pieces together.


Kind Regards

2023-04-03 17-50-41
Samuel Ribeiro

Hello João, how are you?! 


I have a possible idea on how to help you, but I would like to share the "oml" with us to better understand and thus be able to help you better! If you can't, explain to me a little better how you're doing it!


I'm waiting!

UserImage.jpg
João Neto

Hello Samuel, I hope you are well! 

Thank you very much in advance for your help!

 Unfortunately I cannot share the OML of the application because it is being used in a company context and contains sensitive information that I am not authorized to share. However, I will try to detail as much as possible and explain with prints.


The main entities to solve the issue are:



This is the aggregate that I use in the table:



That is the structure of the table, and I need to change the enable property value of the link. It shoud be true if the candidate didn't apply for the contest or false otherwise.




Thank you!

2023-01-11 14-38-58
TESI-Sherwin

Do you mean, you want to add a condition to display the link IF the candidate did not applied yet?

If yes

you can add IF on the row to display the link if the candidate user ID is empty on the candidacy tbl else display none.

or you can add it to the link-enabled property 


also, maybe you can share the join per table you used in the aggregate

UserImage.jpg
João Neto


Hello! Thanks for the answer! 

Yes, that's exactly what I intend to do.

I know which components I can use to hide the link (with if or the enable property). My question is whether I can use something other than the aggregate to fill in the value of the boolean expression.

At this point, I have already managed to implement a solution that works, but to do so I had to add more joins to the aggregate (with the Candidacy table and the Candidate table) and add a boolean output expression based on the condition "Candidate.UserId <> GetUserId()".

However, I would like it to be possible to use the server action that I had already developed that had all the logic that indicated whether or not a candidate could apply for a contest. This would make future changes easier and would be more encapsulated.


Thanks



2022-08-10 06-17-04
Mita

Hi Joao,

I hope you will get a candidate_Id in the candidacy table, if the candidate has applied already?

If not, the candidate is yet to apply.

so, You could you in the enable property of the Button, candidate_Id=NullIdentifier()

I hope this might help you as per what i understood from the tables.

Or in the dataAction, you could have the agrregate and a new calculated attribute in that of type boolean and set its value to false. and in the onafterFetch event of the dataAction, you can check in the forEach loop, if the candidate_Id is Null, you can set the attribute to true. and use the calculated attribute in the enabel property of the button.

Hope it helps.

Mita

UserImage.jpg
João Neto

Hello Mita! Thanks for the answer. 

Yes, it actually helped. 

I used your implementation idea together with the idea of another community member and I managed to do what I wanted! 


Kind Regards,

João

2022-08-10 06-17-04
Mita

Happy to hear that I could help.

All the best!

UserImage.jpg
Craig Rodrigues
Solution

@João Neto Dear João , please find the attached oml. Not really sure if this is what you want. 
A basic explanation about the code adhering to same database design 
1)You'll need two aggregates to achieve as there is nothing in common between contest and candidates because the user id is stored else.  (Could have been easier if the user id was stored in the candidacy table other then extended the user  table)
2)You'll need a calculated attribute in the main aggregate which is false and then second aggregate which is called on demand.
3)After fetching records from the main aggregate launch an event to check if the logged in user is already a contestant for the particular contest and change the calculated attribute accordingly.

So to obtain the end results you wanted , this would be implementation based on your database design and question ,but I would recommend to verify this again to adhere to the best practices.


Contest.oml
UserImage.jpg
João Neto

Hello! 

Thank you very much for the answer, it was exactly what I was looking for. 

I already had a way of getting the data I needed, I just wasn't able to understand how to put the two pieces together.


Kind Regards

2023-10-19 05-09-59
Mangesh Phanse

Hi Jao

there are multiple ways you can implment the solution

1 - Use If widget in table if value satisfies then show link else don't show link

2 - Use enable property of link as shown below

3 -  For more control / better us you can have web block and pass the candidacy id in the webblock. This web block will have data and display logic. 


These are three ways you can implement your soluton

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.