import wixData from ‘wix-data’ ;
$w . onReady ( function () {
$w ( “#dynamicDataset” ). onReady (() => {
const currentItem = $w ( “#dynamicDataset” ). getCurrentItem ();
const recordId = currentItem . _id ;
console . log ( "Current record ID: " , recordId );
console . log ( "Current items: " , currentItem );
});
$w ( “#listRepeater” ). onItemReady (( $w , currentItemData , index ) => {
const recordId = currentItemData . _id ;
console . log ( "Current record ID: " , recordId );
console . log ( "Current items: " , currentItemData );
$w ( #button ${ index }). onClick (() => {
const inputValue = $w ( #input ${ index }). value ;
console . log ( "Input value: " , inputValue );
const ratingValue = inputValue ;
if ( currentItemData . gradeTest === undefined || currentItemData . gradeTest === “” ) {
wixData . insert ( “contact03” , { “gradeTest” : ratingValue })
. then (( results ) => {
const item = results ;
const newRecordId = item . _id ;
console . log ( "New record ID: " , newRecordId );
console . log ( "New gradeTest value: " , ratingValue );
**const** updatedItem = $w ( "#listRepeater" ). data [ index ];
console . log ( "Updated items: " , updatedItem );
$w ( `#text ${ index }`). text = "Grade marked" ;
})
. **catch** (( error ) => {
console . log ( "Error while saving rating value: " , error );
});
} else {
wixData . update ( “contact03” , { “_id” : recordId , “gradeTest” : ratingValue })
. then (() => {
console . log ( “Rating value saved successfully.” );
console . log ( "New gradeTest value: " , ratingValue );
**const** updatedItem = $w ( "#listRepeater" ). data [ index ];
console . log ( "Updated items: " , updatedItem );
})
. **catch** (( error ) => {
console . log ( "Error while saving rating value: " , error );
});
}
});
if ( currentItemData . gradeTest === undefined || currentItemData . gradeTest === “” ) {
$w ( #text ${ index }). text = “Grade not marked” ;
console . log ( “Grade not marked” );
} else {
$w ( #text ${ index }). text = “Grade marked” ;
console . log ( “Grade marked” );
}
});
});