Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom component not opening on edit #1080

Open
karthikCrmwebx opened this issue Jul 1, 2024 · 1 comment
Open

Custom component not opening on edit #1080

karthikCrmwebx opened this issue Jul 1, 2024 · 1 comment

Comments

@karthikCrmwebx
Copy link

karthikCrmwebx commented Jul 1, 2024

im using below custom component like using select they t=can select the value and later user can edit it as per their required value.
im getting the value saved but again if the used want to edit the query builder is not opening

following is the query => [cwx_testoptionset].[set_values] = 'tes@123'

import React, { useEffect, useState } from "react";

const CustomComponent = (props: any) => {
 
  const [selectedOption, setSelectedOption] = useState("");
  const [isEditing, setIsEditing] = useState(false);
  const [editedValue, setEditedValue] = useState("");

  useEffect(() => {

    if (props.value) {
      props.setEditedValueQueryBuilder(props.value);
      setSelectedOption(props.value);
    }
  }, []);

  const handleSelectChange = (event: any) => {
    debugger;
    setSelectedOption(event.target.value);
    setEditedValue(
      props.listValues?.find((el: any) => el?.value === event.target.value)
        ?.title
    );
    props.setValue(event.target.value);
    props.setEditedValueQueryBuilder(event.target.value);
    setIsEditing(true);
  };

  const handleInputChange = (event: any) => {
    setEditedValue(event.target.value);
    debugger;
    props.setValue(event.target.value);
    props.setEditedValueQueryBuilder(event.target.value);
  };

  const handleBlur = () => {
    setIsEditing(false);
    //setSelectedOption(editedValue);
  };

  return (
    <div>
      {isEditing ? (
        <input
          type="text"
          value={editedValue}
          onChange={handleInputChange}
          onBlur={handleBlur}
          autoFocus
        />
      ) : (
        <div>
          our custom
          <select value={selectedOption} onChange={handleSelectChange}>
            <option value="" disabled>
              Select an option
            </option>
            {props.listValues.map(({ value, title }: any) => (
              <option value={value}>{title}</option>
            ))}
          </select>
        </div>
      )}
    </div>
  );
};

export default CustomComponent;
@ukrbublik
Copy link
Owner

I tried to inject your component into example app and it kinda works:

Screen.Recording.2024-07-10.at.17.21.10.mov

Why do you use props.setEditedValueQueryBuilder(event.target.value); ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants