有两个TextInput组件A和B,在B组件输入的时候,需先判断A组件是否有输入内容,如果A组件没有输入内容,B组件不允许输入并提示:请先输入A组件。只有当A组件有输入内容时,B组件才可以正常输入内容并展示。请问该场景如何实现?
@Entry @Component struct OrderIndex { @State message: string = ''; @State isShow: boolean = false; private uiContext: UIContext = this.getUIContext(); build() { Column() { TextInput({ placeholder: 'A' }) .margin({ top: 16, bottom: 16 }) .onChange((val: string) => { this.message = val; if (val !== '') { this.isShow = true; } else { this.isShow = false; } }); TextInput({ placeholder: 'B', }) .focusable(this.isShow) // 是否可以获焦 .onClick(() => { if (!this.isShow) { this.uiContext.getPromptAction().showToast({ message: '请先输入A组件' }); } }); } .height('100%') .margin({ left: 16, right: 16 }); } }