Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Taking my first pass using hooks and running into some issues toggling a boolean value. I can toggle the style when clicking "complete" on an individual item but when I click another "complete" on another item it doesn't fire until you click for the second time.
Below is sandbox URL to help explain what I am running into.
https://codesandbox.io/s/react-to-do-with-hooks-mpqfl
You don't need status to achieve what you are trying to do here.
Here is an updated sandbox which works as expected https://codesandbox.io/s/react-to-do-with-hooks-tvyg2
Your sandbox doesn't work as you are using only 1 variable status to control all your To-Do items.
To explain it better, say there are 2 To-Dos:
1.Learn react
2.Meet friend for lunch
The default value of status is false at first then you mark the first to do as completed and set the value of status as true.
1.Learn react
2.Meet friend for lunch
Everything works as expected as of now.
Now the value of status is true
When you try to mark the 2nd to do as completed with the code here:
newTodos[index].isCompleted = !status;
isCompleted is again assigned false i.e. not completed as !status is false at this point. So no changes occur in your To-Do list.
Following this line you again set status as false here.
setStatus(!status);
Now the new value of status is false.
So when you click on the same To-Do the 2nd time, isCompleted is set to !status i.e true and the list changes to:
1.Learn react
2.Meet friend for lunch
As you were using only 1 variable to track the status of all To-Dos you were facing the observed behaviour
i.e you had to click the button twice to mark it as complete
Related
Within my page (index.tsx), I render a component which can have many children (grandparent.tsx). When I hit delete with no option selected for the input, it deletes fine from my global state (testAtom in atom.ts). However, if I select an input option, when hitting delete, it resets the input option i.e. it doesn't delete in the intended way. The intended behaviour is for it to remove the relevant index from the testAtom.
I believe it is something to do with the useEffect within the input.tsx component. I currently have this here because if the user changes the condition dropdown, I want the value to update accordingly. However, I've been stuck on this for a while and cannot figure it out, so any pointers would be helpful. I would recommend a look at the codesandbox link below, as it will give a clearer picture to the overall makeup of this problem.
CodeSandboxLink
I am developing a ReactJs quiz app in which I am having problem with validating the answers that is in the json.
I did this quiz app using react version 16.8 using state components and fetched the json data and stored in state using map function I have the completed the view part, now I started to validate the quiz and I am struggling in that part.
here is the full code:https://codesandbox.io/s/mystifying-firefly-2d2x5
and also ill add my json link: http://myjson.com/kpop9
I want the answer should be validated, and if user clicks the submit button before attempting all the questions it should show that you have unanswered questions and if user clicks submit after attempting all the quiz it should display the total marks that user got.
Replying to your comment from above, here is your sandbox code slightly edited. You can submit an answer at any time and these are the alerts you should see:
When you don't select an answer: Alert with message No nulls
When answer is wrong: Alert with message wrong
When answer is correct: Alert with message correct
Here is your edited sandbox
The solution provided is only example, and should not be treated as a perfect solution, it's only to give you an idea of how this may work (you may still want to implement the bit, when after submitting the last answer, scores are calculated - for that you may want to store scores)
Explanation:
In this example I decided to add selected_answer variable in the index.js that stores currently selected answer on the form.
Next, I created setAnswer function in index.js which accepts a selected answer as parameter and sets the selected_answer in state to whatever is passed in. You are welcome to implement as many checks for the value that is passed in as you want
setAnswer function is then passed to your Answer component, so when the value is changed, it can be saved inside index.js state
Result component receives the index.js state as a prop. This allows it to have access to current question, the array of all questions and currently selected value
Inside Result component there is a validateAnswer function that is triggered when submit button is clicked. Inside that function I use the props.current_question (which is the index of a question) to extract the whole question object from your JSON file. Next I filter over the array of answers from previously created question object, and I extract the one that has is_right set to 1. Finally, I check if the props.selected_answer is empty, and display a message if so. If it isn't, I check if it equals to the value of previously extracted correct answer object. And voila!
As mentioned before, this is not the best solution, but one that works on top of your code without changing much. Please let me know if you have any further questions, but hope that helps a bit.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Ok, I am trying to make a record and send an email notification/acknowledgement that the record has been recorded. I have a many to many relationship between a Players model and a Lessonhours model. The User model has a one to many with the Players model.
I have run my 'store' method with several different modifications and I finally get my email to send. The problem is that I can't get the array of players that exist and send each an email. The multiple selections from my form are being properly inserted in their respective tables. When it comes to collecting the email data, I have come closest with the following code. The problem with THIS is that I only get one player instead of two or more when they exist. I hope this makes sense. Screenshots below.
Code and screenshot of $request array:
Players Model:
I am not very experienced with this and I am finding it difficult to pinpoint which documentation example to use. How can I get all of the emails addresses for sending after the insertion of record? I appreciate all help offered.
Lessonhours Model:
Store Lessonhours form
User Model
I'm not sure why you're putting an array inside an array for whereIn clause but if request players is already coming through as an array then your should just be able to do:
whereIn('id', $request->players)
Next you're only ever going to be sending one email because you're returning from inside the loop so it's going to send the first player one email and then return a response. To save have a temporary variable that you're not using again you could do:
Players::with('users')->whereIn('id', $request->players)->get()
->each(function ($player) use ($lesshours) {
Mail::to($player->users)->send(new ThankYouForLessonPackagePurchase($lesshours));
});
return back()->with(['success' => 'Player is enrolled in new Lesson Package.']);
You don't have to do the above it's just another way to write it.
Lastly, if you're always going to require player ids to be sent then you might as well add it to the validation array:
'players => 'required',
'players.*' => 'exists:players,id',
Hope this helps!
https://gist.github.com/djdaniels90/948704c58242c4bb08b5
I am having trouble with a dynamically generated quiz structure. I am aware of $parent. scope. I have attempted to implement it but the form is still not working as desired. I have linked the gist site; any help on this would be greatly appreciated.
Each question is a form in itself and the entire quiz is a form of question forms. Each question form contains x number of possible answers. Furthermore, a quiz can have y number of questions. Therefore we have a loop within a loop; ie: we are creating some nested child scopes.
Ultimately, each question can only have one answer, ie: only one checkbox can be clicked for each subforms. I can rather easily hack together a method using pure JS or jquery to grab the form elements but I know there is a way to do this in Angular, I am pretty close I believe but can't get the last little bit. Ideally, I would like either the questions to update corresponding models, which could be created in a array within the controller. Or the form submit action to upload the entire quiz data.
Any help on where I am going wrong would be great.
You are missing one attribute and need a variable for assigning answers to.
The NAME attribute takes care of the grouping and the model cannot be the question object itself, but rather an attribute of the question itself.
<input type="radio" name='{{question.question}}' ng-value="{{answer}}" ng-model="question.answer">
Here's a working version:
http://plnkr.co/edit/fACdq8DGvJel9An87GyA?p=preview
i am trying to change the default value of the Stage Standard Object at Opportunity
The steps i took :
Create a workflow rule with Rule Criteria
Opportunity: Created Date Not EQUAL To null
Evaluation Criteria Evaluate the rule when a record is created.
Add the action as a field update and select the value for the pick list
Activate the rule
but there is nothing happened as the default value remains -NONE-
What am i missing? As am new at salesforce also i don't wanna use trigger or buttons.
There is no option to make the stage field has a default value at the beginning unless you click on Save only in this case the value will be changed
and the steps will work correctly once you click on save button
The selected answer is correct, I've added a few links for anyone else looking for a solution to this issue. Hard to believe this is not standard functionality. Also don't hold your breathe, from the link at the bottom where the idea has been submitted it has been over 9 years and is still on the "PRODUCT TEAM REVIEW". Crazy.
Workarounds:
https://help.salesforce.com/HTViewSolution?id=000003628&language=en_US
https://success.salesforce.com/answers?id=90630000000i4HIAAY
Salesforce idea:
https://success.salesforce.com/ideaView?id=08730000000BrKdAAK