MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / updateNamedCousins

Function updateNamedCousins

code/dependency-injection/public/app.js:4689–4729  ·  view source on GitHub ↗
(rootNode, props)

Source from the content-addressed store, hash-verified

4687}
4688
4689function updateNamedCousins(rootNode, props) {
4690 var name = props.name;
4691 if (props.type === 'radio' && name != null) {
4692 var queryRoot = rootNode;
4693
4694 while (queryRoot.parentNode) {
4695 queryRoot = queryRoot.parentNode;
4696 }
4697
4698 // If `rootNode.form` was non-null, then we could try `form.elements`,
4699 // but that sometimes behaves strangely in IE8. We could also try using
4700 // `form.getElementsByName`, but that will only return direct children
4701 // and won't include inputs that use the HTML5 `form=` attribute. Since
4702 // the input might not even be in a form. It might not even be in the
4703 // document. Let's just use the local `querySelectorAll` to ensure we don't
4704 // miss anything.
4705 var group = queryRoot.querySelectorAll('input[name=' + JSON.stringify('' + name) + '][type="radio"]');
4706
4707 for (var i = 0; i < group.length; i++) {
4708 var otherNode = group[i];
4709 if (otherNode === rootNode || otherNode.form !== rootNode.form) {
4710 continue;
4711 }
4712 // This will throw if radio buttons rendered by different copies of React
4713 // and the same name are rendered into the same form (same as #1939).
4714 // That's probably okay; we don't support it just as we don't support
4715 // mixing React radio buttons with non-React ones.
4716 var otherProps = getFiberCurrentPropsFromNode$1(otherNode);
4717 !otherProps ? invariant(false, 'ReactDOMInput: Mixing React and non-React radio inputs with the same `name` is not supported.') : void 0;
4718
4719 // We need update the tracked value on the named cousin since the value
4720 // was changed but the input saw no event or value set
4721 updateValueIfChanged(otherNode);
4722
4723 // If this is a controlled radio button group, forcing the input that
4724 // was previously checked to update will cause it to be come re-checked
4725 // as appropriate.
4726 updateWrapper(otherNode, otherProps);
4727 }
4728 }
4729}
4730
4731// In Chrome, assigning defaultValue to certain input types triggers input validation.
4732// For number inputs, the display value loses trailing decimal points. For email inputs,

Callers 1

restoreControlledStateFunction · 0.70

Calls 4

invariantFunction · 0.70
updateValueIfChangedFunction · 0.70
updateWrapperFunction · 0.70

Tested by

no test coverage detected