How to Fix 'Each child should have a unique key prop? - dictionary

Hi everyone I would like to display for each element all of its sub-documents.
<div><ul>{designModdulles.map((designModdulle)=><li key={designModdulle.epreuves.nature_epreuve}>{designModdulle.epreuves.nature_epreuve}</li>) }</ul></div>
```
I wanted the sub documents to be displayed` in a map
but i had: Warning: Each child in a list should have a unique "key" prop.

Assuming this is JavaScript, the cause of the issue is that there are duplicate key values. You can use the index of each map entry to create a new key
<div><ul>{designModdulles.map((designModdulle, index)=><li key={designModdulle.epreuves.nature_epreuve + index}>{designModdulle.epreuves.nature_epreuve}</li>) }</ul></div>
You may want to look at the following to see what your choices are (there are other resources as well): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

the problem of the key is resolved, but nothing is displayed in the tag

hello everyone here is the solution:
<ul><li>{designModdulles.map((item,index)=>(<div key={index}>{item.epreuves.map((c, i)=>(<div key={i}>
<h3>{c.code_epreuve}</h3><Button>Insérer notes</Button><Button>Supprimer</Button> </div>) )}</div>))}</li></ul>
thank you

Related

I tried to map function yet throw error (Warning: Each child in a list should have a unique "key" prop.)

Warning: Each child[enter image description here][1] in a list should have a unique "key" prop.
https://i.stack.imgur.com/vAfvR.png
please help me regarding this error
Your key has to be on the outermost element, which in this case is <>.
So rewrite <> to <React.Fragment> and then add a key prop.
<React.Fragment key={id.id}>
...
</React.Fragment>
And please share source code, not screenshots in future questions.

check box in asp.net webform

I need help in check box my problem that when i select any one it gave me message
about my selection but when choose two of check box gave me the last choose of them why and what is the fix please
What is happening is that your Append status is wrong. Instead of appending, you are overwriting the current value. Hence when you choose say two answers, the first is overwritten by the second.
I think the problem is with the syntax of your Append status. Instead of:
Append(Label5.Text =("New Text"));
It should be something like:
Append(Label5.Text).Append("Your new text");
See:
https://msdn.microsoft.com/en-us/library/b4sc8ca8(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

setting default option tag Selected rails

I am generating a list of objects in a option tag using ruby rails .eg
%optgroup
-for #people in c do
%option(value: cac,)
how do i specify a default for the option tag? like a place holder which says please select person, and also how do set it from a cookie or previous selected country.
thanks
Something like this should work(not sure what objects you are working with so the attribute names may need to be changed):
%optgroup
-for #people in c do
-if c.id == default.id
%option{value: c.value, selected: true}
-else
%option{value: c.value}
But the helper that #Iceman linked you allows you to do this in a much simpler way. (http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/grouped_options_for_select)

How to identify HTML object by it's style in HP QTP?

I have a web app and two objects with same class name (no IDs), other attributes also the same. The difference only in same style attributes: one of the objects has "style.display='block'", other has "style.display='none'". (could be other styles attributes!)
How I can identify first object by it's style attributes? For thing such names, I could use "attribute/name", but is there anything like this for style?
Thank you!
Edit: My original answer was true for its time but UFT has since added support for style/ properties. You can now use style/display:=none".
This is indeed a limitation in QTP :(
One thing you can do is write a small WebExtesibility project which adds the display property to your test object.
I know this is an old question, but it is accepted as if there is not a simple solution for it, while there is:
Yes you can, but it has to be an attribute on the actual object and not inherited by parent objects (well, I had negative results on that situation).
' Make a new description for the object
Set desc = Description.Create()
desc("micclass").Value = "WebButton" ' assuming webbutton here
desc("Class Name").Value = "YourClassName"
' This returns a collection with buttons matching your description
Set Btns = Browser("YourBrowser").Page("YourPage").ChildObjects(desc)
For BtnIndex = 0 to Btns.Count - 1
' This will show you the display style, so you can make a selector here
MsgBox "Button " & BtnIndex & " has display style: " & Btns(BtnIndex).Object.currentStyle.Display
Next

Cucumber/Webrat: follow link by CSS class?

is it possible to follow a link by it's class name instead of the id, text or title? Given I have (haha, cucumber insider he?) the following html code:
<div id="some_information_container">
Translation here
</div>
I do not want to match by text because I'd have to care about the translation values in my tests
I want to have my buttons look all the same style, so I will use the CSS class.
I don't want to assign a id to every single link, because some of them are perfectly identified through the container and the link class
Is there anything I missed in Cucumber/Webrat? Or do you have some advices to solve this in a better way?
Thanks for your help and best regards,
Joe
edit: I found an interesting discussion going on about this topic right here - seems to remain an open issue for now. Do you have any other solutions for this?
Here's how I did it with cucumber, hope it helps. The # in the step definition helps the CSS understand whats going on.
This only works with ID's not class names
Step Definition
Then /^(?:|I )should see ([^\"]*) within a div with id "([^\"]*)"$/ do |text, selector|
# checks for text within a specified div id
within "##{selector}" do |content|
if defined?(Spec::Rails::Matchers)
content.should contain(text)
else
hc = Webrat::Matchers::HasContent.new(text)
assert hc.matches?(content), hc.failure_message
end
end
end
Feature
Scenario Outline: Create Project
When I fill in name with <title>
And I select <data_type> from data_type
And I press "Create"
Then I should see <title> within a div with id "specifications"
Scenarios: Search Terms and Results
| data_type | title |
| Books | A Book Title |
Here is how to assert text within an element with the class name of "edit_botton"
Then I should see "Translation here" within "[#class='edit_button']"
How about find('a.some-class').click?
I'm not very familiar with the WebRat API, but what about using a DOM lookup to get the reference ID of the class that you are looking for then passing that to the click_link function?
Here's a link to some javascript to retrieve an item by class.
http://mykenta.blogspot.com/2007/10/getelementbyclass-revisited.html
Now that I think about it, what about using Javascript to just simply change it to some random ID then clicking that?
Either way, that should work until the frugal debate of a name to include the getbyclass function as is resolved.
Does have_tag work for you?
have_tag('a.edit_button')

Resources