| | |
| | | if (!data.name || data.name.length < 2) return false; |
| | | try { |
| | | const response = await this.createTerm(data); |
| | | |
| | | let currentField = this.selector.currentField(); |
| | | if (!response.success) { |
| | | // Term already exists - still add it |
| | | if (response.term && response.term.id) { |
| | | this.selector.setMessage(true, `Using existing "${response.term.name}"`); |
| | | this.selector.setMessage(currentField,true, `Using existing "${response.term.name}"`); |
| | | return response.term; |
| | | } |
| | | |
| | | // Other failure |
| | | this.selector.setMessage(true, response.message || 'Creation failed', false); |
| | | this.selector.setMessage(currentField,true, response.message || 'Creation failed', false); |
| | | return false; |
| | | } |
| | | if (response.term?.pending) { |
| | | // Term requires approval |
| | | this.selector.setMessage( |
| | | currentField, |
| | | true, |
| | | `"${data.name}" submitted for approval`, |
| | | false |