How to use isDirtyWithModifiers method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

dom-props.js

Source: dom-props.js Github

copy
1/* @flow */
2
3import { isDef, isUndef, extend, toNumber } from 'shared/util'
4
5function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
6  if (isUndef(oldVnode.data.domProps) && isUndef(vnode.data.domProps)) {
7    return
8  }
9  let key, cur
10  const elm: any = vnode.elm
11  const oldProps = oldVnode.data.domProps || {}
12  let props = vnode.data.domProps || {}
13  // clone observed objects, as the user probably wants to mutate it
14  if (isDef(props.__ob__)) {
15    props = vnode.data.domProps = extend({}, props)
16  }
17
18  for (key in oldProps) {
19    if (isUndef(props[key])) {
20      elm[key] = ''
21    }
22  }
23  for (key in props) {
24    cur = props[key]
25    // ignore children if the node has textContent or innerHTML,
26    // as these will throw away existing DOM nodes and cause removal errors
27    // on subsequent patches (#3360)
28    if (key === 'textContent' || key === 'innerHTML') {
29      if (vnode.children) vnode.children.length = 0
30      if (cur === oldProps[key]) continue
31      // #6601 work around Chrome version <= 55 bug where single textNode
32      // replaced by innerHTML/textContent retains its parentNode property
33      if (elm.childNodes.length === 1) {
34        elm.removeChild(elm.childNodes[0])
35      }
36    }
37
38    if (key === 'value') {
39      // store value as _value as well since
40      // non-string values will be stringified
41      elm._value = cur
42      // avoid resetting cursor position when value is the same
43      const strCur = isUndef(cur) ? '' : String(cur)
44      if (shouldUpdateValue(elm, strCur)) {
45        elm.value = strCur
46      }
47    } else {
48      elm[key] = cur
49    }
50  }
51}
52
53// check platforms/web/util/attrs.js acceptValue
54type acceptValueElm = HTMLInputElement | HTMLSelectElement | HTMLOptionElement;
55
56function shouldUpdateValue (elm: acceptValueElm, checkVal: string): boolean {
57  return (!elm.composing && (
58    elm.tagName === 'OPTION' ||
59    isNotInFocusAndDirty(elm, checkVal) ||
60    isDirtyWithModifiers(elm, checkVal)
61  ))
62}
63
64function isNotInFocusAndDirty (elm: acceptValueElm, checkVal: string): boolean {
65  // return true when textbox (.number and .trim) loses focus and its value is
66  // not equal to the updated value
67  let notInFocus = true
68  // #6157
69  // work around IE bug when accessing document.activeElement in an iframe
70  try { notInFocus = document.activeElement !== elm } catch (e) {}
71  return notInFocus && elm.value !== checkVal
72}
73
74function isDirtyWithModifiers (elm: any, newVal: string): boolean {
75  const value = elm.value
76  const modifiers = elm._vModifiers // injected by v-model runtime
77  if (isDef(modifiers)) {
78    if (modifiers.lazy) {
79      // inputs with lazy should only be updated when not in focus
80      return false
81    }
82    if (modifiers.number) {
83      return toNumber(value) !== toNumber(newVal)
84    }
85    if (modifiers.trim) {
86      return value.trim() !== newVal.trim()
87    }
88  }
89  return value !== newVal
90}
91
92export default {
93  create: updateDOMProps,
94  update: updateDOMProps
95}
96
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)