简体   繁体   English

添加 value 属性后,React Fabric TextField 变为只读

[英]React Fabric TextField becomes read only after adding value property

I have been trying to figure out how to handle value changes in React Fabric TextFields.我一直在试图弄清楚如何处理 React Fabric TextFields 中的值变化。 The problem is every time I set the value property, the component becomes read only.问题是每次设置value属性时,组件都会变为只读。 If is use the defaultValue property, everything works fine, apart from the fact I need this input to be controlled.如果使用defaultValue属性,则一切正常,除了我需要控制此输入的事实。 I am using React Fabric inside a SharePoint Framework solution.我在 SharePoint 框架解决方案中使用 React Fabric。

What I currently have is this:我目前拥有的是:

  ...

  this.state = {
    title: ''
  }

  this.handleInputChange = this.handleInputChange.bind(this);
}

public handleInputChange(id, value) {
  this.setState({
    [id]: value
  });
}

public render(): React.ReactElement<IQuoteAppProps> {
  return (
    <TextField
      label='Title'
      onChanged={(value) => this.handleInputChange('title', value)}
      value={this.state.title}
      required
     />
   )
}

Does anyone know how to correctly set this up?有谁知道如何正确设置? I have included two screenshots as well.我还包括了两个屏幕截图。

Edit: I literally copied and pasted an example from the developer page mentioned below and it is still not working.编辑:我从下面提到的开发人员页面中复制并粘贴了一个示例,但它仍然无法正常工作。 The component on their website is working fine and can be edited.他们网站上的组件运行良好,可以编辑。 The only thing I now have in mind is whether React Fabric is not colliding with something inside SharePoint Framework.我现在唯一想到的是 React Fabric 是否没有与 SharePoint 框架内的某些内容发生冲突。

Office UI Fabric TextField: https://developer.microsoft.com/en-us/fabric#/components/textfield Office UI Fabric TextField: https : //developer.microsoft.com/en-us/fabric#/components/textfield

React 开发工具截图 HTML 元素检查器屏幕截图

After creating a new SPFx project and testing it there, everything was working fine.在创建一个新的 SPFx 项目并在那里对其进行测试后,一切正常。 I decided to delete the node_modules folder and run npm install to install all the packages from scratch.我决定删除node_modules文件夹并运行npm install从头开始安装所有包。 It magically started working.它神奇地开始工作。

Does anybody know what exactly could be causing this?有谁知道究竟是什么导致了这种情况?

This should caused by your handleInputChange function, as you not update TextField vaule, you could insert a alert to this function and you would see the new key entered.这应该是由您的 handleInputChange 函数引起的,因为您没有更新 TextField vaule,您可以向该函数插入警报,您会看到输入的新键。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:在函数中使用状态值后,无法分配给对象的只读属性“值” - TypeError: Cannot assign to read only property 'value' of object react after using the value of state in a function 无法将值设置为react中的只读属性 - Can't set value to read-only property in react 组件第一次渲染后,对象变为只读 - Object becomes read-only after the component rendered first time 仅在添加全局导航保护后,Vue路由器才会引发“无法读取未定义的属性&#39;匹配&#39;”错误 - Vue-router throwing “Cannot read property 'matched' of undefined” error only after adding global navigation guards 仅在导入对象的 js 文件中添加脚本后才出错:无法读取 null () 的属性“addEventListener” - Error ONLY after adding script in the js file for Importing Objects : Cannot read property 'addEventListener' of null () 如何在添加新文本后使用Javascript保留Textfield的值? - How to keep the Value of a Textfield with Javascript after adding new ones? React js无法分配给只读属性 - React js Cannot assign to read only property 反应无法在 onKeyPress 读取 null 的属性“值” - REACT Cannot read property 'value' of null at onKeyPress 无法在React项目中读取未定义的属性“值”? - Cannot read property 'value' of undefined in react project? REACT TypeError:无法读取未定义的属性“值” - REACT TypeError: Cannot read property 'value' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM