Urgent.News

What's breaking now, across thousands of outlets.

Tech

A New Challenger to CSS Selectors: WebForms Place Criteria (WPC)

One of the major improvements in WebForms Core 2.1 is the expansion of WebForms Place Criteria (WPC) . WPC is a DSL built into WebForms Core for selecting, filtering, and manipulating HTML elements and groups of DOM elements. At its basic level, WPC provides selectors for finding elements by ID, Name, Tag, Class, and Attribute , as well as navigating through children, parents, the current…

WebForms Core 2.1 has introduced significant enhancements to the WebForms Place Criteria (WPC) system. WPC is a domain-specific language embedded within WebForms Core that enables the selection, filtering, and manipulation of HTML elements and their relationships within the Document Object Model (DOM). At its core, WPC offers a range of selectors for identifying elements based on ID, Name, Tag, Class, and Attribute attributes, as well as navigating through various DOM elements such as children, parents, the current element, and higher-level elements like Document, Window, HTML, Head, Root, and more.

Furthermore, elements can be selected by their index, all matching elements can be retrieved, and selection paths can be combined using functions like Child() and Parent(). The functionality of WPC is built to complement CSS Selectors, while also extending their capabilities.

WPC's primary function is to locate HTML elements (and beyond) that are targeted for modification. Unlike CSS Selectors, WPC provides a more comprehensive selection mechanism that includes the ability to filter and evaluate already-selected elements based on diverse criteria. This Criteria layer of WPC goes beyond basic selection techniques (like ID, Class, Tag) by enabling developers to filter and assess selected elements through various attributes, text content, tag names, visibility, enabled or disabled state, checked state, DOM relationships, position, ranges, and sets of elements.

The article focuses specifically on the Criteria layer of WPC and illustrates how it can be utilized to refine element selections, evaluate their properties and state, navigate their relationships, and combine multiple conditions to produce precise DOM selections that extend far beyond the simple examples of selecting elements by ID or class.

The article provides several examples demonstrating the capabilities of WPC:

1. Filtering by Text and Numeric Value: This example selects all 'td' elements and filters them based on their text content. For instance, elements with text content greater than or equal to 10 are set to green (e.g., 17, 11, 15, 20), while those with text content less than 10 are set to red (e.g., 6, 5, 9). This showcases WPC's ability to perform numeric comparisons on the text content of elements.

2. Combining Criteria with Different Operators: This example changes the font size of elements whose text content is greater than 10. The condition '!t :10' uses the '!' operator to reverse the comparison, selecting elements whose text content is not less than or equal to 10, effectively selecting elements with text content greater than 10. Another example selects 'td' elements whose text content is exactly 20.

3. Searching for Text Inside Elements: WPC can search for specific text within elements. For example, it can add text 'Find: Adriano' to any element containing the word 'Adriano'. This demonstrates WPC's capability to perform textual searches within elements.

4. Selecting Elements by Attribute: WPC can select elements based on an attribute and its value. For instance, it can select input elements where the attribute 'att1' ends with '9', selecting elements with attribute values such as '123456789', '119', and '59'.

5. Selecting Elements by Tag Name: This example demonstrates selecting all 'input' elements in a form and applying a yellow border to them. It shows WPC's ability to select elements based on their tag names.

6. Checking Visibility: The article shows how WPC can select elements that are not visible. Using the '?!v' condition, it selects elements that have 'display:none' applied, effectively finding elements that are hidden from view.

7. Finding Disabled Elements: This example identifies disabled input elements by applying the '!v' condition, which selects elements that are not in the visible state. This highlights WPC's utility in targeting elements based on their enabled or disabled state.

These examples showcase the versatility and power of WPC, demonstrating its potential to go far beyond simple element selection through ID or class. WPC provides a comprehensive and flexible system for manipulating and refining selections within the DOM, making it a valuable tool for developers working within the WebForms framework.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

🛡️ IMDSv1 vs IMDSv2 en EC2: SSRF, métricas, riesgos y una migración segura

¿Qué riesgo existe realmente al mantener IMDSv1 habilitado en una instancia EC2? En 2019, el incidente de Capital One mostró que el acceso no autorizado al EC2 Instance Metadata Service (IMDS) puede…

  • IMDSv1 uses direct HTTP request to 169.254.169.254, while IMDSv2 adds token-based session
  • Verify CloudWatch metrics like MetadataNoToken during migration to ensure no IMDSv1 calls
  • Different tools use different names for same configuration, so understand both options

More from Sunday 6 September →