- Split `definitions/attribute.py` into separate files under `definitions/attributes/`. - Added `__init__.py` for simplified imports. - Improved code organization and maintainability.
24 lines
920 B
Python
24 lines
920 B
Python
from typing import List, Optional
|
|
from dataclasses import dataclass, field
|
|
from .Attribute import Attribute
|
|
|
|
@dataclass
|
|
class selectAttribute(Attribute):
|
|
"""Class for select attributes."""
|
|
options: List[str] = None
|
|
|
|
def __post_init__(self):
|
|
"""Post-initialization to set the HTML input type."""
|
|
self.html_input_type = "select"
|
|
self.valid_comparisons = {"eq", "ne"} # eq, or not eq, to the ref attrib
|
|
|
|
def validate(self) -> Optional[str]:
|
|
"""Validate select-specific attributes."""
|
|
error = super().validate()
|
|
if error:
|
|
return error
|
|
if not self.options:
|
|
return f"options cannot be empty for attribute '{self.attrib_name}'."
|
|
if self.default_val is not None and self.default_val not in self.options:
|
|
return f"default_val must be one of the options for attribute '{self.attrib_name}'."
|
|
return None |