Skip to content

Commit

Permalink
run on enter for various components (#188)
Browse files Browse the repository at this point in the history
Co-authored-by: Red-Giuliano <red.giuliano@zero-true.com>
  • Loading branch information
Red-Giuliano and Red-Giuliano authored Feb 29, 2024
1 parent aaa59fe commit 47ca79b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion zt_backend/models/components/number_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
class NumberInput(ZTComponent):
"""Number input allows a user to input an arbitrary number. Can be a float or an integer"""
component: str = Field("v-number-field", description="Vue component name")
hint: Optional[str] = Field('Press Enter to Submit', description="Hint text for the number input")
value: Union[int,float,None] = Field (None,description="The input number value")
placeholder: Optional[Union[int,float]] = Field(None, description="Placeholder number")
label: Optional[str] = Field(None, description="Label for the number input")
readonly: Optional[bool] = Field(None, description="If true, the input is read-only")
disabled: Optional[bool] = Field(None, description="If true, the input is disabled")
type: str = Field('number',description="Ensures that only numbers are accepted on the frontend")
triggerEvent: str = Field('input',description="Trigger event to send code to the backend")
triggerEvent: str = Field(None,description="Trigger event to send code to the backend")

@validator('value', always=True) #TODO: debug and replace with field validator
def get_value_from_global_state(cls, value, values):
Expand Down
3 changes: 2 additions & 1 deletion zt_backend/models/components/text_area_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
class TextArea(ZTComponent):
"""Text area input allows a user to input arbitrary text. This is meant for larger text inputs"""
component: str = Field("v-textarea", description="Vue component name")
hint: Optional[str] = Field('Press Enter to Submit', description="Hint text for the text input")
value: str = Field ('',description="The input text value")
placeholder: Optional[str] = Field(None, description="Placeholder text")
label: Optional[str] = Field(None, description="Label for the text input")
readonly: Optional[bool] = Field(None, description="If true, the input is read-only")
disabled: Optional[bool] = Field(None, description="If true, the input is disabled")
triggerEvent: str = Field('input',description="Trigger event to send code to the backend")
triggerEvent: str = Field(None,description="Trigger event to send code to the backend")

@validator('value', always=True) #TODO: debug and replace with field validator
def get_value_from_global_state(cls, value, values):
Expand Down
3 changes: 2 additions & 1 deletion zt_backend/models/components/text_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
class TextInput(ZTComponent):
"""Text input allows a user to input arbitrary text. This is meant for short text inputs"""
component: str = Field("v-text-field", description="Vue component name")
hint: Optional[str] = Field('Press Enter to Submit', description="Hint text for the text input")
value: str = Field ('', description="The input text value")
placeholder: Optional[str] = Field(None, description="Placeholder text")
label: Optional[str] = Field(None, description="Label for the text input")
readonly: Optional[bool] = Field(None, description="If true, the input is read-only")
disabled: Optional[bool] = Field(None, description="If true, the input is disabled")
triggerEvent: str = Field('input',description="Trigger event to send code to the backend")
triggerEvent: str = Field(None,description="Trigger event to send code to the backend")

@validator('value', always=True) #TODO: debug and replace with field validator
def get_value_from_global_state(cls, value, values):
Expand Down
7 changes: 7 additions & 0 deletions zt_frontend/src/components/CodeComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
v-bind="componentBind(component)"
v-model="component.value"
@click="clickedButton(component)"
@keydown="handleEnterPress($event, component.id,component.component, component.value)"
@[component.triggerEvent]="
runCode(true, component.id, component.value)
"
Expand Down Expand Up @@ -385,6 +386,12 @@ export default {
return newObj;
}, {});
},
handleEnterPress(e: any, id: string,component_type: any, value: any) {
// Run code when Enter is pressed in a text, number or text are field
if (e.key === "Enter" && (component_type === "v-text-field" || component_type === "v-textarea" || component_type === "v-number-field")) {
this.runCode(true, id, value);
}
},
clickedButton(component: any) {
if (component.component === "v-btn" || component.component === "v-timer") {
component.value = true;
Expand Down

0 comments on commit 47ca79b

Please sign in to comment.